1 /* 2 * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting 3 * Copyright (c) 2002-2004 Atheros Communications, Inc. 4 * 5 * Permission to use, copy, modify, and/or distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 * 17 * $FreeBSD$ 18 */ 19 #include "opt_ah.h" 20 21 #include "ah.h" 22 #include "ah_internal.h" 23 #include "ah_devid.h" 24 25 #include "ar5210/ar5210.h" 26 #include "ar5210/ar5210reg.h" 27 #include "ar5210/ar5210phy.h" 28 29 #include "ah_eeprom_v1.h" 30 31 static HAL_BOOL ar5210GetChannelEdges(struct ath_hal *, 32 uint16_t flags, uint16_t *low, uint16_t *high); 33 static HAL_BOOL ar5210GetChipPowerLimits(struct ath_hal *ah, 34 struct ieee80211_channel *chan); 35 36 static void ar5210ConfigPCIE(struct ath_hal *ah, HAL_BOOL restore, 37 HAL_BOOL power_on); 38 static void ar5210DisablePCIE(struct ath_hal *ah); 39 40 static const struct ath_hal_private ar5210hal = {{ 41 .ah_magic = AR5210_MAGIC, 42 43 .ah_getRateTable = ar5210GetRateTable, 44 .ah_detach = ar5210Detach, 45 46 /* Reset Functions */ 47 .ah_reset = ar5210Reset, 48 .ah_phyDisable = ar5210PhyDisable, 49 .ah_disable = ar5210Disable, 50 .ah_configPCIE = ar5210ConfigPCIE, 51 .ah_disablePCIE = ar5210DisablePCIE, 52 .ah_setPCUConfig = ar5210SetPCUConfig, 53 .ah_perCalibration = ar5210PerCalibration, 54 .ah_perCalibrationN = ar5210PerCalibrationN, 55 .ah_resetCalValid = ar5210ResetCalValid, 56 .ah_setTxPowerLimit = ar5210SetTxPowerLimit, 57 .ah_getChanNoise = ath_hal_getChanNoise, 58 59 /* Transmit functions */ 60 .ah_updateTxTrigLevel = ar5210UpdateTxTrigLevel, 61 .ah_setupTxQueue = ar5210SetupTxQueue, 62 .ah_setTxQueueProps = ar5210SetTxQueueProps, 63 .ah_getTxQueueProps = ar5210GetTxQueueProps, 64 .ah_releaseTxQueue = ar5210ReleaseTxQueue, 65 .ah_resetTxQueue = ar5210ResetTxQueue, 66 .ah_getTxDP = ar5210GetTxDP, 67 .ah_setTxDP = ar5210SetTxDP, 68 .ah_numTxPending = ar5210NumTxPending, 69 .ah_startTxDma = ar5210StartTxDma, 70 .ah_stopTxDma = ar5210StopTxDma, 71 .ah_setupTxDesc = ar5210SetupTxDesc, 72 .ah_setupXTxDesc = ar5210SetupXTxDesc, 73 .ah_fillTxDesc = ar5210FillTxDesc, 74 .ah_procTxDesc = ar5210ProcTxDesc, 75 .ah_getTxIntrQueue = ar5210GetTxIntrQueue, 76 .ah_reqTxIntrDesc = ar5210IntrReqTxDesc, 77 .ah_getTxCompletionRates = ar5210GetTxCompletionRates, 78 .ah_setTxDescLink = ar5210SetTxDescLink, 79 .ah_getTxDescLink = ar5210GetTxDescLink, 80 .ah_getTxDescLinkPtr = ar5210GetTxDescLinkPtr, 81 82 /* RX Functions */ 83 .ah_getRxDP = ar5210GetRxDP, 84 .ah_setRxDP = ar5210SetRxDP, 85 .ah_enableReceive = ar5210EnableReceive, 86 .ah_stopDmaReceive = ar5210StopDmaReceive, 87 .ah_startPcuReceive = ar5210StartPcuReceive, 88 .ah_stopPcuReceive = ar5210StopPcuReceive, 89 .ah_setMulticastFilter = ar5210SetMulticastFilter, 90 .ah_setMulticastFilterIndex = ar5210SetMulticastFilterIndex, 91 .ah_clrMulticastFilterIndex = ar5210ClrMulticastFilterIndex, 92 .ah_getRxFilter = ar5210GetRxFilter, 93 .ah_setRxFilter = ar5210SetRxFilter, 94 .ah_setupRxDesc = ar5210SetupRxDesc, 95 .ah_procRxDesc = ar5210ProcRxDesc, 96 .ah_rxMonitor = ar5210RxMonitor, 97 .ah_aniPoll = ar5210AniPoll, 98 .ah_procMibEvent = ar5210MibEvent, 99 100 /* Misc Functions */ 101 .ah_getCapability = ar5210GetCapability, 102 .ah_setCapability = ar5210SetCapability, 103 .ah_getDiagState = ar5210GetDiagState, 104 .ah_getMacAddress = ar5210GetMacAddress, 105 .ah_setMacAddress = ar5210SetMacAddress, 106 .ah_getBssIdMask = ar5210GetBssIdMask, 107 .ah_setBssIdMask = ar5210SetBssIdMask, 108 .ah_setRegulatoryDomain = ar5210SetRegulatoryDomain, 109 .ah_setLedState = ar5210SetLedState, 110 .ah_writeAssocid = ar5210WriteAssocid, 111 .ah_gpioCfgInput = ar5210GpioCfgInput, 112 .ah_gpioCfgOutput = ar5210GpioCfgOutput, 113 .ah_gpioGet = ar5210GpioGet, 114 .ah_gpioSet = ar5210GpioSet, 115 .ah_gpioSetIntr = ar5210Gpio0SetIntr, 116 .ah_getTsf32 = ar5210GetTsf32, 117 .ah_getTsf64 = ar5210GetTsf64, 118 .ah_resetTsf = ar5210ResetTsf, 119 .ah_detectCardPresent = ar5210DetectCardPresent, 120 .ah_updateMibCounters = ar5210UpdateMibCounters, 121 .ah_getRfGain = ar5210GetRfgain, 122 .ah_getDefAntenna = ar5210GetDefAntenna, 123 .ah_setDefAntenna = ar5210SetDefAntenna, 124 .ah_getAntennaSwitch = ar5210GetAntennaSwitch, 125 .ah_setAntennaSwitch = ar5210SetAntennaSwitch, 126 .ah_setSifsTime = ar5210SetSifsTime, 127 .ah_getSifsTime = ar5210GetSifsTime, 128 .ah_setSlotTime = ar5210SetSlotTime, 129 .ah_getSlotTime = ar5210GetSlotTime, 130 .ah_setAckTimeout = ar5210SetAckTimeout, 131 .ah_getAckTimeout = ar5210GetAckTimeout, 132 .ah_setAckCTSRate = ar5210SetAckCTSRate, 133 .ah_getAckCTSRate = ar5210GetAckCTSRate, 134 .ah_setCTSTimeout = ar5210SetCTSTimeout, 135 .ah_getCTSTimeout = ar5210GetCTSTimeout, 136 .ah_setDecompMask = ar5210SetDecompMask, 137 .ah_setCoverageClass = ar5210SetCoverageClass, 138 .ah_get11nExtBusy = ar5210Get11nExtBusy, 139 .ah_getMibCycleCounts = ar5210GetMibCycleCounts, 140 .ah_enableDfs = ar5210EnableDfs, 141 .ah_getDfsThresh = ar5210GetDfsThresh, 142 /* XXX procRadarEvent */ 143 /* XXX isFastClockEnabled */ 144 145 /* Key Cache Functions */ 146 .ah_getKeyCacheSize = ar5210GetKeyCacheSize, 147 .ah_resetKeyCacheEntry = ar5210ResetKeyCacheEntry, 148 .ah_isKeyCacheEntryValid = ar5210IsKeyCacheEntryValid, 149 .ah_setKeyCacheEntry = ar5210SetKeyCacheEntry, 150 .ah_setKeyCacheEntryMac = ar5210SetKeyCacheEntryMac, 151 152 /* Power Management Functions */ 153 .ah_setPowerMode = ar5210SetPowerMode, 154 .ah_getPowerMode = ar5210GetPowerMode, 155 156 /* Beacon Functions */ 157 .ah_setBeaconTimers = ar5210SetBeaconTimers, 158 .ah_beaconInit = ar5210BeaconInit, 159 .ah_setStationBeaconTimers = ar5210SetStaBeaconTimers, 160 .ah_resetStationBeaconTimers = ar5210ResetStaBeaconTimers, 161 .ah_getNextTBTT = ar5210GetNextTBTT, 162 163 /* Interrupt Functions */ 164 .ah_isInterruptPending = ar5210IsInterruptPending, 165 .ah_getPendingInterrupts = ar5210GetPendingInterrupts, 166 .ah_getInterrupts = ar5210GetInterrupts, 167 .ah_setInterrupts = ar5210SetInterrupts }, 168 169 .ah_getChannelEdges = ar5210GetChannelEdges, 170 .ah_getWirelessModes = ar5210GetWirelessModes, 171 .ah_eepromRead = ar5210EepromRead, 172 #ifdef AH_SUPPORT_WRITE_EEPROM 173 .ah_eepromWrite = ar5210EepromWrite, 174 #endif 175 .ah_getChipPowerLimits = ar5210GetChipPowerLimits, 176 }; 177 178 static HAL_BOOL ar5210FillCapabilityInfo(struct ath_hal *ah); 179 180 /* 181 * Attach for an AR5210 part. 182 */ 183 static struct ath_hal * 184 ar5210Attach(uint16_t devid, HAL_SOFTC sc, HAL_BUS_TAG st, HAL_BUS_HANDLE sh, 185 uint16_t *eepromdata, HAL_STATUS *status) 186 { 187 #define N(a) (sizeof(a)/sizeof(a[0])) 188 struct ath_hal_5210 *ahp; 189 struct ath_hal *ah; 190 uint32_t revid, pcicfg; 191 uint16_t eeval; 192 HAL_STATUS ecode; 193 int i; 194 195 HALDEBUG(AH_NULL, HAL_DEBUG_ATTACH, 196 "%s: devid 0x%x sc %p st %p sh %p\n", __func__, devid, 197 sc, (void*) st, (void*) sh); 198 199 /* NB: memory is returned zero'd */ 200 ahp = ath_hal_malloc(sizeof (struct ath_hal_5210)); 201 if (ahp == AH_NULL) { 202 HALDEBUG(AH_NULL, HAL_DEBUG_ANY, 203 "%s: no memory for state block\n", __func__); 204 ecode = HAL_ENOMEM; 205 goto bad; 206 } 207 ah = &ahp->ah_priv.h; 208 /* set initial values */ 209 OS_MEMCPY(&ahp->ah_priv, &ar5210hal, sizeof(struct ath_hal_private)); 210 ah->ah_sc = sc; 211 ah->ah_st = st; 212 ah->ah_sh = sh; 213 214 ah->ah_devid = devid; /* NB: for AH_DEBUG_ALQ */ 215 AH_PRIVATE(ah)->ah_devid = devid; 216 AH_PRIVATE(ah)->ah_subvendorid = 0; /* XXX */ 217 218 AH_PRIVATE(ah)->ah_powerLimit = AR5210_MAX_RATE_POWER; 219 AH_PRIVATE(ah)->ah_tpScale = HAL_TP_SCALE_MAX; /* no scaling */ 220 221 ahp->ah_powerMode = HAL_PM_UNDEFINED; 222 ahp->ah_staId1Defaults = 0; 223 ahp->ah_rssiThr = INIT_RSSI_THR; 224 ahp->ah_sifstime = (u_int) -1; 225 ahp->ah_slottime = (u_int) -1; 226 ahp->ah_acktimeout = (u_int) -1; 227 ahp->ah_ctstimeout = (u_int) -1; 228 229 if (!ar5210ChipReset(ah, AH_NULL)) { /* reset chip */ 230 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: chip reset failed\n", 231 __func__); 232 ecode = HAL_EIO; 233 goto bad; 234 } 235 236 /* Read Revisions from Chips */ 237 AH_PRIVATE(ah)->ah_macVersion = 1; 238 AH_PRIVATE(ah)->ah_macRev = OS_REG_READ(ah, AR_SREV) & 0xff; 239 AH_PRIVATE(ah)->ah_phyRev = OS_REG_READ(ah, AR_PHY_CHIPID); 240 AH_PRIVATE(ah)->ah_analog2GhzRev = 0; 241 242 /* Read Radio Chip Rev Extract */ 243 OS_REG_WRITE(ah, (AR_PHY_BASE + (0x34 << 2)), 0x00001c16); 244 for (i = 0; i < 4; i++) 245 OS_REG_WRITE(ah, (AR_PHY_BASE + (0x20 << 2)), 0x00010000); 246 revid = (OS_REG_READ(ah, AR_PHY_BASE + (256 << 2)) >> 28) & 0xf; 247 248 /* Chip labelling is 1 greater than revision register for AR5110 */ 249 AH_PRIVATE(ah)->ah_analog5GhzRev = ath_hal_reverseBits(revid, 4) + 1; 250 251 /* 252 * Read all the settings from the EEPROM and stash 253 * ones we'll use later. 254 */ 255 pcicfg = OS_REG_READ(ah, AR_PCICFG); 256 OS_REG_WRITE(ah, AR_PCICFG, pcicfg | AR_PCICFG_EEPROMSEL); 257 ecode = ath_hal_v1EepromAttach(ah); 258 if (ecode != HAL_OK) { 259 goto eebad; 260 } 261 ecode = ath_hal_eepromGet(ah, AR_EEP_REGDMN_0, &eeval); 262 if (ecode != HAL_OK) { 263 HALDEBUG(ah, HAL_DEBUG_ANY, 264 "%s: cannot read regulatory domain from EEPROM\n", 265 __func__); 266 goto eebad; 267 } 268 AH_PRIVATE(ah)->ah_currentRD = eeval; 269 ecode = ath_hal_eepromGet(ah, AR_EEP_MACADDR, ahp->ah_macaddr); 270 if (ecode != HAL_OK) { 271 HALDEBUG(ah, HAL_DEBUG_ANY, 272 "%s: error getting mac address from EEPROM\n", __func__); 273 goto eebad; 274 } 275 OS_REG_WRITE(ah, AR_PCICFG, pcicfg); /* disable EEPROM access */ 276 277 AH_PRIVATE(ah)->ah_getNfAdjust = ar5210GetNfAdjust; 278 279 /* 280 * Got everything we need now to setup the capabilities. 281 */ 282 (void) ar5210FillCapabilityInfo(ah); 283 284 HALDEBUG(ah, HAL_DEBUG_ATTACH, "%s: return\n", __func__); 285 286 return ah; 287 eebad: 288 OS_REG_WRITE(ah, AR_PCICFG, pcicfg); /* disable EEPROM access */ 289 bad: 290 if (ahp) 291 ath_hal_free(ahp); 292 if (status) 293 *status = ecode; 294 return AH_NULL; 295 #undef N 296 } 297 298 void 299 ar5210Detach(struct ath_hal *ah) 300 { 301 HALDEBUG(ah, HAL_DEBUG_ATTACH, "%s:\n", __func__); 302 303 HALASSERT(ah != AH_NULL); 304 HALASSERT(ah->ah_magic == AR5210_MAGIC); 305 306 ath_hal_eepromDetach(ah); 307 ath_hal_free(ah); 308 } 309 310 /* 311 * Store the channel edges for the requested operational mode 312 */ 313 static HAL_BOOL 314 ar5210GetChannelEdges(struct ath_hal *ah, 315 uint16_t flags, uint16_t *low, uint16_t *high) 316 { 317 if (flags & IEEE80211_CHAN_5GHZ) { 318 *low = 5120; 319 *high = 5430; 320 return AH_TRUE; 321 } else { 322 return AH_FALSE; 323 } 324 } 325 326 static HAL_BOOL 327 ar5210GetChipPowerLimits(struct ath_hal *ah, struct ieee80211_channel *chan) 328 { 329 /* XXX fill in, this is just a placeholder */ 330 HALDEBUG(ah, HAL_DEBUG_ATTACH, 331 "%s: no min/max power for %u/0x%x\n", 332 __func__, chan->ic_freq, chan->ic_flags); 333 chan->ic_maxpower = AR5210_MAX_RATE_POWER; 334 chan->ic_minpower = 0; 335 return AH_TRUE; 336 } 337 338 static void 339 ar5210ConfigPCIE(struct ath_hal *ah, HAL_BOOL restore, HAL_BOOL power_off) 340 { 341 } 342 343 static void 344 ar5210DisablePCIE(struct ath_hal *ah) 345 { 346 } 347 348 /* 349 * Fill all software cached or static hardware state information. 350 */ 351 static HAL_BOOL 352 ar5210FillCapabilityInfo(struct ath_hal *ah) 353 { 354 struct ath_hal_private *ahpriv = AH_PRIVATE(ah); 355 HAL_CAPABILITIES *pCap = &ahpriv->ah_caps; 356 357 pCap->halWirelessModes |= HAL_MODE_11A; 358 359 pCap->halLow5GhzChan = 5120; 360 pCap->halHigh5GhzChan = 5430; 361 362 pCap->halSleepAfterBeaconBroken = AH_TRUE; 363 pCap->halPSPollBroken = AH_FALSE; 364 pCap->halNumMRRetries = 1; /* No hardware MRR support */ 365 pCap->halNumTxMaps = 1; /* Single TX ptr per descr */ 366 367 pCap->halTotalQueues = HAL_NUM_TX_QUEUES; 368 pCap->halKeyCacheSize = 64; 369 370 /* XXX not needed */ 371 pCap->halChanHalfRate = AH_FALSE; 372 pCap->halChanQuarterRate = AH_FALSE; 373 374 /* 375 * RSSI uses the combined field; some 11n NICs may use 376 * the control chain RSSI. 377 */ 378 pCap->halUseCombinedRadarRssi = AH_TRUE; 379 380 if (ath_hal_eepromGetFlag(ah, AR_EEP_RFKILL)) { 381 /* 382 * Setup initial rfsilent settings based on the EEPROM 383 * contents. Pin 0, polarity 0 is fixed; record this 384 * using the EEPROM format found in later parts. 385 */ 386 ahpriv->ah_rfsilent = SM(0, AR_EEPROM_RFSILENT_GPIO_SEL) 387 | SM(0, AR_EEPROM_RFSILENT_POLARITY); 388 ahpriv->ah_rfkillEnabled = AH_TRUE; 389 pCap->halRfSilentSupport = AH_TRUE; 390 } 391 392 pCap->halTstampPrecision = 15; /* NB: s/w extended from 13 */ 393 pCap->halIntrMask = (HAL_INT_COMMON - HAL_INT_BNR) 394 | HAL_INT_RX 395 | HAL_INT_TX 396 | HAL_INT_FATAL 397 ; 398 399 pCap->hal4kbSplitTransSupport = AH_TRUE; 400 pCap->halHasRxSelfLinkedTail = AH_TRUE; 401 402 ahpriv->ah_rxornIsFatal = AH_TRUE; 403 return AH_TRUE; 404 } 405 406 static const char* 407 ar5210Probe(uint16_t vendorid, uint16_t devid) 408 { 409 if (vendorid == ATHEROS_VENDOR_ID && 410 (devid == AR5210_PROD || devid == AR5210_DEFAULT)) 411 return "Atheros 5210"; 412 return AH_NULL; 413 } 414 AH_CHIP(AR5210, ar5210Probe, ar5210Attach); 415