📄 ar5210_misc.c
字号:
/* * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting * Copyright (c) 2002-2005 Atheros Communications, Inc. * All rights reserved. * * $Id: ar5210_misc.c,v 1.1.1.1 2006/09/12 03:45:22 steven Exp $ */#include "opt_ah.h"#ifdef AH_SUPPORT_AR5210#include "ah.h"#include "ah_internal.h"#include "ar5210/ar5210.h"#include "ar5210/ar5210reg.h"#include "ar5210/ar5210phy.h"#define AR_NUM_GPIO 6 /* 6 GPIO bits */#define AR_GPIOD_MASK 0x2f /* 6-bit mask */voidar5210GetMacAddress(struct ath_hal *ah, u_int8_t *mac){ struct ath_hal_5210 *ahp = AH5210(ah); OS_MEMCPY(mac, ahp->ah_macaddr, IEEE80211_ADDR_LEN);}HAL_BOOLar5210SetMacAddress(struct ath_hal *ah, const u_int8_t *mac){ struct ath_hal_5210 *ahp = AH5210(ah); OS_MEMCPY(ahp->ah_macaddr, mac, IEEE80211_ADDR_LEN); return AH_TRUE;}voidar5210GetBssIdMask(struct ath_hal *ah, u_int8_t *mask){ static const u_int8_t ones[IEEE80211_ADDR_LEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; OS_MEMCPY(mask, ones, IEEE80211_ADDR_LEN);}HAL_BOOLar5210SetBssIdMask(struct ath_hal *ah, const u_int8_t *mask){ return AH_FALSE;}/* * Read 16 bits of data from the specified EEPROM offset. */HAL_BOOLar5210EepromRead(struct ath_hal *ah, u_int off, u_int16_t *data){ (void) OS_REG_READ(ah, AR_EP_AIR(off)); /* activate read op */ if (!ath_hal_wait(ah, AR_EP_STA, AR_EP_STA_RDCMPLT | AR_EP_STA_RDERR, AR_EP_STA_RDCMPLT)) { HALDEBUG(ah, "%s: read failed for entry 0x%x\n", __func__, AR_EP_AIR(off)); return AH_FALSE; } *data = OS_REG_READ(ah, AR_EP_RDATA) & 0xffff; return AH_TRUE;}#ifdef AH_SUPPORT_WRITE_EEPROM/* * Write 16 bits of data to the specified EEPROM offset. */HAL_BOOLar5210EepromWrite(struct ath_hal *ah, u_int off, u_int16_t data){ OS_REG_WRITE(ah, AR_EP_AIR(off), data); /* active write op */ if (!ath_hal_wait(ah, AR_EP_STA, AR_EP_STA_WRCMPLT | AR_EP_STA_WRERR, AR_EP_STA_WRCMPLT)) { HALDEBUG(ah, "%s: write failed for entry 0x%x, data 0x%x\n", __func__, AR_EP_AIR(off), data); return AH_FALSE; } return AH_TRUE;}#endif /* AH_SUPPORT_WRITE_EEPROM *//* * Attempt to change the cards operating regulatory domain to the given value * Returns: A_EINVAL for an unsupported regulatory domain. * A_HARDWARE for an unwritable EEPROM or bad EEPROM version */HAL_BOOLar5210SetRegulatoryDomain(struct ath_hal *ah, u_int16_t regDomain, HAL_STATUS *status){ struct ath_hal_5210 *ahp = AH5210(ah);#ifdef AH_SUPPORT_WRITE_REGDOMAIN u_int32_t pcicfg;#endif HAL_STATUS ecode; if (AH_PRIVATE(ah)->ah_currentRD == regDomain) { ecode = HAL_EINVAL; goto bad; } /* * Check if EEPROM is configured to allow this; must * be a proper version and the protection bits must * permit re-writing that segment of the EEPROM. */ HALASSERT(ahp->ah_eeversion == 1); if (ahp->ah_eeprotect & AR_EEPROM_PROTOTECT_WP_128_191) { ecode = HAL_EEWRITE; goto bad; }#ifdef AH_SUPPORT_WRITE_REGDOMAIN /* * Enable the EEPROM for writing and set the value. */ pcicfg = OS_REG_READ(ah, AR_PCICFG); OS_REG_WRITE(ah, AR_PCICFG, pcicfg | AR_PCICFG_EEPROMSEL); if (ar5210EepromWrite(ah, AR_EEPROM_REG_DOMAIN, regDomain)) { HALDEBUG(ah, "%s: set regulatory domain to %u (0x%x)\n", __func__, regDomain, regDomain); AH_PRIVATE(ah)->ah_currentRD = regDomain; ecode = HAL_OK; } else { ecode = HAL_EIO; } OS_REG_WRITE(ah, AR_PCICFG, pcicfg); if (ecode == HAL_OK) return AH_TRUE; /* fall thru... */#else ecode = HAL_EIO; /* disallow all writes */#endifbad: if (status) *status = ecode; return AH_FALSE;}/* * Return the wireless modes (a,b,g,t) supported by hardware. * * This value is what is actually supported by the hardware * and is unaffected by regulatory/country code settings. * */u_intar5210GetWirelessModes(struct ath_hal *ah){ /* XXX could enable turbo mode but can't do all rates */ return HAL_MODE_11A;}/* * Accessor to get rfkill from private EEPROM structure */HAL_BOOLar5210GetRfKill(struct ath_hal *ah){ return (AH5210(ah)->ah_rfKill != 0);}/* * Called if RfKill is supported (according to EEPROM). Set the interrupt and * GPIO values so the ISR and can disable RF on a switch signal */voidar5210EnableRfKill(struct ath_hal *ah){ u_int32_t val; /* * If radio disable switch connection to GPIO bit 0 is enabled * program GPIO interrupt. * If rfkill bit on eeprom is 1, setupeeprommap routine has already * verified that it is a later version of eeprom, it has a place for * rfkill bit and it is set to 1, indicating that GPIO bit 0 hardware * connection is present. */ val = ar5210GpioGet(ah, 0); ar5210Gpio0SetIntr(ah, 0, (val == 0));}/* * Configure GPIO Output lines */HAL_BOOLar5210GpioCfgOutput(struct ath_hal *ah, u_int32_t gpio){ HALASSERT(gpio < AR_NUM_GPIO); OS_REG_WRITE(ah, AR_GPIOCR, (OS_REG_READ(ah, AR_GPIOCR) &~ AR_GPIOCR_ALL(gpio)) | AR_GPIOCR_OUT1(gpio)); return AH_TRUE;}/* * Configure GPIO Input lines */HAL_BOOLar5210GpioCfgInput(struct ath_hal *ah, u_int32_t gpio){ HALASSERT(gpio < AR_NUM_GPIO); OS_REG_WRITE(ah, AR_GPIOCR, (OS_REG_READ(ah, AR_GPIOCR) &~ AR_GPIOCR_ALL(gpio)) | AR_GPIOCR_IN(gpio)); return AH_TRUE;}/* * Once configured for I/O - set output lines */HAL_BOOLar5210GpioSet(struct ath_hal *ah, u_int32_t gpio, u_int32_t val){ u_int32_t reg; HALASSERT(gpio < AR_NUM_GPIO); reg = OS_REG_READ(ah, AR_GPIODO); reg &= ~(1 << gpio); reg |= (val&1) << gpio; OS_REG_WRITE(ah, AR_GPIODO, reg); return AH_TRUE;}/* * Once configured for I/O - get input lines */u_int32_tar5210GpioGet(struct ath_hal *ah, u_int32_t gpio){ if (gpio < AR_NUM_GPIO) { u_int32_t val = OS_REG_READ(ah, AR_GPIODI); val = ((val & AR_GPIOD_MASK) >> gpio) & 0x1; return val; } else { return 0xffffffff; }}/* * Set the GPIO 0 Interrupt */voidar5210Gpio0SetIntr(struct ath_hal *ah, u_int gpio, u_int32_t ilevel){ u_int32_t val = OS_REG_READ(ah, AR_GPIOCR); /* Clear the bits that we will modify. */ val &= ~(AR_GPIOCR_INT_SEL(gpio) | AR_GPIOCR_INT_SELH | AR_GPIOCR_INT_ENA | AR_GPIOCR_ALL(gpio)); val |= AR_GPIOCR_INT_SEL(gpio) | AR_GPIOCR_INT_ENA; if (ilevel) val |= AR_GPIOCR_INT_SELH; /* Don't need to change anything for low level interrupt. */ OS_REG_WRITE(ah, AR_GPIOCR, val); /* Change the interrupt mask. */ ar5210SetInterrupts(ah, AH5210(ah)->ah_maskReg | HAL_INT_GPIO);}/* * Change the LED blinking pattern to correspond to the connectivity */voidar5210SetLedState(struct ath_hal *ah, HAL_LED_STATE state){ u_int32_t val; val = OS_REG_READ(ah, AR_PCICFG); switch (state) { case HAL_LED_INIT: val &= ~(AR_PCICFG_LED_PEND | AR_PCICFG_LED_ACT); break; case HAL_LED_RUN: /* normal blink when connected */ val &= ~AR_PCICFG_LED_PEND; val |= AR_PCICFG_LED_ACT; break; default: val |= AR_PCICFG_LED_PEND; val &= ~AR_PCICFG_LED_ACT; break; } OS_REG_WRITE(ah, AR_PCICFG, val);}/* * Return 1 or 2 for the corresponding antenna that is in use */u_intar5210GetDefAntenna(struct ath_hal *ah){ u_int32_t val = OS_REG_READ(ah, AR_STA_ID1); return (val & AR_STA_ID1_DEFAULT_ANTENNA ? 2 : 1);}voidar5210SetDefAntenna(struct ath_hal *ah, u_int antenna){ u_int32_t val = OS_REG_READ(ah, AR_STA_ID1); if (antenna != (val & AR_STA_ID1_DEFAULT_ANTENNA ? 2 : 1)) { /* * Antenna change requested, force a toggle of the default. */ OS_REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_DEFAULT_ANTENNA); }}/* * Change association related fields programmed into the hardware. * Writing a valid BSSID to the hardware effectively enables the hardware * to synchronize its TSF to the correct beacons and receive frames coming * from that BSSID. It is called by the SME JOIN operation. */voidar5210WriteAssocid(struct ath_hal *ah, const u_int8_t *bssid, u_int16_t assocId){ struct ath_hal_5210 *ahp = AH5210(ah); /* XXX save bssid for possible re-use on reset */ OS_MEMCPY(ahp->ah_bssid, bssid, IEEE80211_ADDR_LEN); OS_REG_WRITE(ah, AR_BSS_ID0, LE_READ_4(ahp->ah_bssid)); OS_REG_WRITE(ah, AR_BSS_ID1, LE_READ_2(ahp->ah_bssid+4) | ((assocId & 0x3fff)<<AR_BSS_ID1_AID_S)); if (assocId == 0) OS_REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_NO_PSPOLL); else OS_REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_NO_PSPOLL);}/* * Get the current hardware tsf for stamlme. */u_int64_tar5210GetTsf64(struct ath_hal *ah){ u_int64_t tsf; /* XXX sync multi-word read? */ tsf = OS_REG_READ(ah, AR_TSF_U32); tsf = (tsf << 32) | OS_REG_READ(ah, AR_TSF_L32); return tsf;}/* * Get the current hardware tsf for stamlme. */u_int32_tar5210GetTsf32(struct ath_hal *ah){ return OS_REG_READ(ah, AR_TSF_L32);}/* * Reset the current hardware tsf for stamlme */voidar5210ResetTsf(struct ath_hal *ah){ u_int32_t val = OS_REG_READ(ah, AR_BEACON); OS_REG_WRITE(ah, AR_BEACON, val | AR_BEACON_RESET_TSF);}/* * Grab a semi-random value from hardware registers - may not * change often */u_int32_tar5210GetRandomSeed(struct ath_hal *ah){ u_int32_t nf; nf = (OS_REG_READ(ah, AR_PHY_BASE + (25 << 2)) >> 19) & 0x1ff; if (nf & 0x100) nf = 0 - ((nf ^ 0x1ff) + 1); return (OS_REG_READ(ah, AR_TSF_U32) ^ OS_REG_READ(ah, AR_TSF_L32) ^ nf);}/* * Detect if our card is present */HAL_BOOLar5210DetectCardPresent(struct ath_hal *ah){ /* * Read the Silicon Revision register and compare that * to what we read at attach time. If the same, we say * a card/device is present. */ return (AH_PRIVATE(ah)->ah_macRev == (OS_REG_READ(ah, AR_SREV) & 0xff));}/* * Update MIB Counters */voidar5210UpdateMibCounters(struct ath_hal *ah, HAL_MIB_STATS *stats){ stats->ackrcv_bad += OS_REG_READ(ah, AR_ACK_FAIL); stats->rts_bad += OS_REG_READ(ah, AR_RTS_FAIL); stats->fcs_bad += OS_REG_READ(ah, AR_FCS_FAIL); stats->rts_good += OS_REG_READ(ah, AR_RTS_OK); stats->beacons += OS_REG_READ(ah, AR_BEACON_CNT);}HAL_BOOLar5210SetSlotTime(struct ath_hal *ah, u_int us){ struct ath_hal_5210 *ahp = AH5210(ah); if (us < HAL_SLOT_TIME_6 || us > ath_hal_mac_usec(ah, 0xffff)) { HALDEBUG(ah, "%s: bad slot time %u\n", __func__, us); ahp->ah_slottime = (u_int) -1; /* restore default handling */ return AH_FALSE; } else { /* convert to system clocks */ OS_REG_WRITE(ah, AR_SLOT_TIME, ath_hal_mac_clks(ah, us)); ahp->ah_slottime = us; return AH_TRUE; }}u_intar5210GetSlotTime(struct ath_hal *ah){ u_int clks = OS_REG_READ(ah, AR_SLOT_TIME) & 0xffff; return ath_hal_mac_usec(ah, clks); /* convert from system clocks */}HAL_BOOLar5210SetAckTimeout(struct ath_hal *ah, u_int us){ struct ath_hal_5210 *ahp = AH5210(ah); if (us > ath_hal_mac_usec(ah, MS(0xffffffff, AR_TIME_OUT_ACK))) { HALDEBUG(ah, "%s: bad ack timeout %u\n", __func__, us); ahp->ah_acktimeout = (u_int) -1; /* restore default handling */ return AH_FALSE; } else { /* convert to system clocks */ OS_REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_ACK, ath_hal_mac_clks(ah, us)); ahp->ah_acktimeout = us; return AH_TRUE; }}u_intar5210GetAckTimeout(struct ath_hal *ah){ u_int clks = MS(OS_REG_READ(ah, AR_TIME_OUT), AR_TIME_OUT_ACK); return ath_hal_mac_usec(ah, clks); /* convert from system clocks */}HAL_BOOLar5210SetCTSTimeout(struct ath_hal *ah, u_int us){ struct ath_hal_5210 *ahp = AH5210(ah); if (us > ath_hal_mac_usec(ah, MS(0xffffffff, AR_TIME_OUT_CTS))) { HALDEBUG(ah, "%s: bad cts timeout %u\n", __func__, us); ahp->ah_ctstimeout = (u_int) -1; /* restore default handling */ return AH_FALSE; } else { /* convert to system clocks */ OS_REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_CTS, ath_hal_mac_clks(ah, us)); ahp->ah_ctstimeout = us; return AH_TRUE; }}u_intar5210GetCTSTimeout(struct ath_hal *ah){ u_int clks = MS(OS_REG_READ(ah, AR_TIME_OUT), AR_TIME_OUT_CTS); return ath_hal_mac_usec(ah, clks); /* convert from system clocks */}HAL_BOOLar5210SetDecompMask(struct ath_hal *ah, u_int16_t keyidx, int en){ /* nothing to do */ return AH_TRUE;}voidar5210SetCoverageClass(struct ath_hal *ah, u_int8_t coverageclass, int now){}/* * Control Adaptive Noise Immunity Parameters */HAL_BOOLar5210AniControl(struct ath_hal *ah, HAL_ANI_CMD cmd, int param){ return AH_FALSE;}voidar5210AniPoll(struct ath_hal *ah, const HAL_NODE_STATS *stats, HAL_CHANNEL *chan){}voidar5210MibEvent(struct ath_hal *ah, const HAL_NODE_STATS *stats){}#define AR_DIAG_SW_DIS_CRYPTO (AR_DIAG_SW_DIS_ENC | AR_DIAG_SW_DIS_DEC)HAL_STATUSar5210GetCapability(struct ath_hal *ah, HAL_CAPABILITY_TYPE type, u_int32_t capability, u_int32_t *result){ switch (type) { case HAL_CAP_CIPHER: /* cipher handled in hardware */ return (capability == HAL_CIPHER_WEP ? HAL_OK : HAL_ENOTSUPP); default: return ath_hal_getcapability(ah, type, capability, result); }}HAL_BOOLar5210SetCapability(struct ath_hal *ah, HAL_CAPABILITY_TYPE type, u_int32_t capability, u_int32_t setting, HAL_STATUS *status){ switch (type) { case HAL_CAP_DIAG: /* hardware diagnostic support */ /* * NB: could split this up into virtual capabilities, * (e.g. 1 => ACK, 2 => CTS, etc.) but it hardly * seems worth the additional complexity. */#ifdef AH_DEBUG AH_PRIVATE(ah)->ah_diagreg = setting;#else AH_PRIVATE(ah)->ah_diagreg = setting & 0x6; /* ACK+CTS */#endif OS_REG_WRITE(ah, AR_DIAG_SW, AH_PRIVATE(ah)->ah_diagreg); return AH_TRUE; default: return ath_hal_setcapability(ah, type, capability, setting, status); }}HAL_BOOLar5210GetDiagState(struct ath_hal *ah, int request, const void *args, u_int32_t argsize, void **result, u_int32_t *resultsize){#ifdef AH_PRIVATE_DIAG u_int32_t pcicfg; HAL_BOOL ok; switch (request) { case HAL_DIAG_EEPROM: /* XXX */ break; case HAL_DIAG_EEREAD: if (argsize != sizeof(u_int16_t)) return AH_FALSE; pcicfg = OS_REG_READ(ah, AR_PCICFG); OS_REG_WRITE(ah, AR_PCICFG, pcicfg | AR_PCICFG_EEPROMSEL); ok = ath_hal_eepromRead(ah, *(const u_int16_t *)args, *result); OS_REG_WRITE(ah, AR_PCICFG, pcicfg); if (ok) *resultsize = sizeof(u_int16_t); return ok;#ifdef AH_SUPPORT_WRITE_EEPROM case HAL_DIAG_EEWRITE: { HAL_DIAG_EEVAL *ee; if (argsize != sizeof(HAL_DIAG_EEVAL)) return AH_FALSE; ee = (HAL_DIAG_EEVAL *)args; pcicfg = OS_REG_READ(ah, AR_PCICFG); OS_REG_WRITE(ah, AR_PCICFG, pcicfg | AR_PCICFG_EEPROMSEL); ok = ath_hal_eepromWrite(ah, ee->ee_off, ee->ee_data); OS_REG_WRITE(ah, AR_PCICFG, pcicfg); return ok; }#endif /* AH_SUPPORT_WRITE_EEPROM */ }#endif return ath_hal_getdiagstate(ah, request, args, argsize, result, resultsize);}voidar5210ArDisable(struct ath_hal *ah){}voidar5210ResetAR(struct ath_hal *ah){}voidar5210ArEnable(struct ath_hal *ah){}voidar5210XrEnable(struct ath_hal *ah){}voidar5210XrDisable(struct ath_hal *ah){}#endif /* AH_SUPPORT_AR5210 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -