Deleted Added
sdiff udiff text old ( 185380 ) new ( 185406 )
full compact
1/*
2 * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
3 * Copyright (c) 2002-2008 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 * $Id: ar5212_attach.c,v 1.18 2008/11/19 22:10:42 sam Exp $
18 */
19#include "opt_ah.h"
20
21#ifdef AH_SUPPORT_AR5212
22
23#if !defined(AH_SUPPORT_5112) && \
24 !defined(AH_SUPPORT_5111) && \
25 !defined(AH_SUPPORT_2413) && \
26 !defined(AH_SUPPORT_5413) && \
27 !defined(AH_SUPPORT_AR5312)
28#error "No 5212 RF support defined"
29#endif
30
31#include "ah.h"
32#include "ah_internal.h"
33#include "ah_devid.h"
34
35#include "ar5212/ar5212.h"
36#include "ar5212/ar5212reg.h"
37#include "ar5212/ar5212phy.h"
38#ifdef AH_SUPPORT_AR5311
39#include "ar5212/ar5311reg.h"
40#endif
41
42#define AH_5212_COMMON
43#include "ar5212/ar5212.ini"
44
45static const struct ath_hal_private ar5212hal = {{
46 .ah_magic = AR5212_MAGIC,
47 .ah_abi = HAL_ABI_VERSION,
48 .ah_countryCode = CTRY_DEFAULT,
49
50 .ah_getRateTable = ar5212GetRateTable,
51 .ah_detach = ar5212Detach,
52
53 /* Reset Functions */
54 .ah_reset = ar5212Reset,
55 .ah_phyDisable = ar5212PhyDisable,
56 .ah_disable = ar5212Disable,
57 .ah_setPCUConfig = ar5212SetPCUConfig,
58 .ah_perCalibration = ar5212PerCalibration,
59 .ah_perCalibrationN = ar5212PerCalibrationN,
60 .ah_resetCalValid = ar5212ResetCalValid,
61 .ah_setTxPowerLimit = ar5212SetTxPowerLimit,
62 .ah_getChanNoise = ath_hal_getChanNoise,
63
64 /* Transmit functions */
65 .ah_updateTxTrigLevel = ar5212UpdateTxTrigLevel,
66 .ah_setupTxQueue = ar5212SetupTxQueue,
67 .ah_setTxQueueProps = ar5212SetTxQueueProps,
68 .ah_getTxQueueProps = ar5212GetTxQueueProps,
69 .ah_releaseTxQueue = ar5212ReleaseTxQueue,
70 .ah_resetTxQueue = ar5212ResetTxQueue,
71 .ah_getTxDP = ar5212GetTxDP,
72 .ah_setTxDP = ar5212SetTxDP,
73 .ah_numTxPending = ar5212NumTxPending,
74 .ah_startTxDma = ar5212StartTxDma,
75 .ah_stopTxDma = ar5212StopTxDma,
76 .ah_setupTxDesc = ar5212SetupTxDesc,
77 .ah_setupXTxDesc = ar5212SetupXTxDesc,
78 .ah_fillTxDesc = ar5212FillTxDesc,
79 .ah_procTxDesc = ar5212ProcTxDesc,
80 .ah_getTxIntrQueue = ar5212GetTxIntrQueue,
81 .ah_reqTxIntrDesc = ar5212IntrReqTxDesc,
82
83 /* RX Functions */
84 .ah_getRxDP = ar5212GetRxDP,
85 .ah_setRxDP = ar5212SetRxDP,
86 .ah_enableReceive = ar5212EnableReceive,
87 .ah_stopDmaReceive = ar5212StopDmaReceive,
88 .ah_startPcuReceive = ar5212StartPcuReceive,
89 .ah_stopPcuReceive = ar5212StopPcuReceive,
90 .ah_setMulticastFilter = ar5212SetMulticastFilter,
91 .ah_setMulticastFilterIndex = ar5212SetMulticastFilterIndex,
92 .ah_clrMulticastFilterIndex = ar5212ClrMulticastFilterIndex,
93 .ah_getRxFilter = ar5212GetRxFilter,
94 .ah_setRxFilter = ar5212SetRxFilter,
95 .ah_setupRxDesc = ar5212SetupRxDesc,
96 .ah_procRxDesc = ar5212ProcRxDesc,
97 .ah_rxMonitor = ar5212AniPoll,
98 .ah_procMibEvent = ar5212ProcessMibIntr,
99
100 /* Misc Functions */
101 .ah_getCapability = ar5212GetCapability,
102 .ah_setCapability = ar5212SetCapability,
103 .ah_getDiagState = ar5212GetDiagState,
104 .ah_getMacAddress = ar5212GetMacAddress,
105 .ah_setMacAddress = ar5212SetMacAddress,
106 .ah_getBssIdMask = ar5212GetBssIdMask,
107 .ah_setBssIdMask = ar5212SetBssIdMask,
108 .ah_setRegulatoryDomain = ar5212SetRegulatoryDomain,
109 .ah_setLedState = ar5212SetLedState,
110 .ah_writeAssocid = ar5212WriteAssocid,
111 .ah_gpioCfgInput = ar5212GpioCfgInput,
112 .ah_gpioCfgOutput = ar5212GpioCfgOutput,
113 .ah_gpioGet = ar5212GpioGet,
114 .ah_gpioSet = ar5212GpioSet,
115 .ah_gpioSetIntr = ar5212GpioSetIntr,
116 .ah_getTsf32 = ar5212GetTsf32,
117 .ah_getTsf64 = ar5212GetTsf64,
118 .ah_resetTsf = ar5212ResetTsf,
119 .ah_detectCardPresent = ar5212DetectCardPresent,
120 .ah_updateMibCounters = ar5212UpdateMibCounters,
121 .ah_getRfGain = ar5212GetRfgain,
122 .ah_getDefAntenna = ar5212GetDefAntenna,
123 .ah_setDefAntenna = ar5212SetDefAntenna,
124 .ah_getAntennaSwitch = ar5212GetAntennaSwitch,
125 .ah_setAntennaSwitch = ar5212SetAntennaSwitch,
126 .ah_setSifsTime = ar5212SetSifsTime,
127 .ah_getSifsTime = ar5212GetSifsTime,
128 .ah_setSlotTime = ar5212SetSlotTime,
129 .ah_getSlotTime = ar5212GetSlotTime,
130 .ah_setAckTimeout = ar5212SetAckTimeout,
131 .ah_getAckTimeout = ar5212GetAckTimeout,
132 .ah_setAckCTSRate = ar5212SetAckCTSRate,
133 .ah_getAckCTSRate = ar5212GetAckCTSRate,
134 .ah_setCTSTimeout = ar5212SetCTSTimeout,
135 .ah_getCTSTimeout = ar5212GetCTSTimeout,
136 .ah_setDecompMask = ar5212SetDecompMask,
137 .ah_setCoverageClass = ar5212SetCoverageClass,
138
139 /* Key Cache Functions */
140 .ah_getKeyCacheSize = ar5212GetKeyCacheSize,
141 .ah_resetKeyCacheEntry = ar5212ResetKeyCacheEntry,
142 .ah_isKeyCacheEntryValid = ar5212IsKeyCacheEntryValid,
143 .ah_setKeyCacheEntry = ar5212SetKeyCacheEntry,
144 .ah_setKeyCacheEntryMac = ar5212SetKeyCacheEntryMac,
145
146 /* Power Management Functions */
147 .ah_setPowerMode = ar5212SetPowerMode,
148 .ah_getPowerMode = ar5212GetPowerMode,
149
150 /* Beacon Functions */
151 .ah_setBeaconTimers = ar5212SetBeaconTimers,
152 .ah_beaconInit = ar5212BeaconInit,
153 .ah_setStationBeaconTimers = ar5212SetStaBeaconTimers,
154 .ah_resetStationBeaconTimers = ar5212ResetStaBeaconTimers,
155
156 /* Interrupt Functions */
157 .ah_isInterruptPending = ar5212IsInterruptPending,
158 .ah_getPendingInterrupts = ar5212GetPendingInterrupts,
159 .ah_getInterrupts = ar5212GetInterrupts,
160 .ah_setInterrupts = ar5212SetInterrupts },
161
162 .ah_getChannelEdges = ar5212GetChannelEdges,
163 .ah_getWirelessModes = ar5212GetWirelessModes,
164 .ah_eepromRead = ar5212EepromRead,
165#ifdef AH_SUPPORT_WRITE_EEPROM
166 .ah_eepromWrite = ar5212EepromWrite,
167#endif
168 .ah_gpioCfgOutput = ar5212GpioCfgOutput,
169 .ah_gpioCfgInput = ar5212GpioCfgInput,
170 .ah_gpioGet = ar5212GpioGet,
171 .ah_gpioSet = ar5212GpioSet,
172 .ah_gpioSetIntr = ar5212GpioSetIntr,
173 .ah_getChipPowerLimits = ar5212GetChipPowerLimits,
174};
175
176/*
177 * Disable PLL when in L0s as well as receiver clock when in L1.
178 * This power saving option must be enabled through the Serdes.
179 *
180 * Programming the Serdes must go through the same 288 bit serial shift
181 * register as the other analog registers. Hence the 9 writes.
182 *
183 * XXX Clean up the magic numbers.
184 */
185static void
186configurePciePowerSave(struct ath_hal *ah)
187{
188 OS_REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
189 OS_REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
190
191 /* RX shut off when elecidle is asserted */
192 OS_REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
193 OS_REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
194 OS_REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
195
196 /* Shut off PLL and CLKREQ active in L1 */
197 OS_REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
198 OS_REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
199 OS_REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
200 OS_REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
201
202 /* Load the new settings */
203 OS_REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
204}
205
206uint32_t
207ar5212GetRadioRev(struct ath_hal *ah)
208{
209 uint32_t val;
210 int i;
211
212 /* Read Radio Chip Rev Extract */
213 OS_REG_WRITE(ah, AR_PHY(0x34), 0x00001c16);
214 for (i = 0; i < 8; i++)
215 OS_REG_WRITE(ah, AR_PHY(0x20), 0x00010000);
216 val = (OS_REG_READ(ah, AR_PHY(256)) >> 24) & 0xff;
217 val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4);
218 return ath_hal_reverseBits(val, 8);
219}
220
221static void
222ar5212AniSetup(struct ath_hal *ah)
223{
224 static const struct ar5212AniParams aniparams = {
225 .maxNoiseImmunityLevel = 4, /* levels 0..4 */
226 .totalSizeDesired = { -55, -55, -55, -55, -62 },
227 .coarseHigh = { -14, -14, -14, -14, -12 },
228 .coarseLow = { -64, -64, -64, -64, -70 },
229 .firpwr = { -78, -78, -78, -78, -80 },
230 .maxSpurImmunityLevel = 2, /* NB: depends on chip rev */
231 .cycPwrThr1 = { 2, 4, 6, 8, 10, 12, 14, 16 },
232 .maxFirstepLevel = 2, /* levels 0..2 */
233 .firstep = { 0, 4, 8 },
234 .ofdmTrigHigh = 500,
235 .ofdmTrigLow = 200,
236 .cckTrigHigh = 200,
237 .cckTrigLow = 100,
238 .rssiThrHigh = 40,
239 .rssiThrLow = 7,
240 .period = 100,
241 };
242 if (AH_PRIVATE(ah)->ah_macVersion < AR_SREV_VERSION_GRIFFIN) {
243 struct ar5212AniParams tmp;
244 OS_MEMCPY(&tmp, &aniparams, sizeof(struct ar5212AniParams));
245 tmp.maxSpurImmunityLevel = 7; /* Venice and earlier */
246 ar5212AniAttach(ah, &tmp, &tmp, AH_TRUE);
247 } else
248 ar5212AniAttach(ah, &aniparams, &aniparams, AH_TRUE);
249}
250
251/*
252 * Attach for an AR5212 part.
253 */
254void
255ar5212InitState(struct ath_hal_5212 *ahp, uint16_t devid, HAL_SOFTC sc,
256 HAL_BUS_TAG st, HAL_BUS_HANDLE sh, HAL_STATUS *status)
257{
258#define N(a) (sizeof(a)/sizeof(a[0]))
259 static const uint8_t defbssidmask[IEEE80211_ADDR_LEN] =
260 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
261 struct ath_hal *ah;
262
263 ah = &ahp->ah_priv.h;
264 /* set initial values */
265 OS_MEMCPY(&ahp->ah_priv, &ar5212hal, sizeof(struct ath_hal_private));
266 ah->ah_sc = sc;
267 ah->ah_st = st;
268 ah->ah_sh = sh;
269
270 ah->ah_devid = devid; /* NB: for alq */
271 AH_PRIVATE(ah)->ah_devid = devid;
272 AH_PRIVATE(ah)->ah_subvendorid = 0; /* XXX */
273
274 AH_PRIVATE(ah)->ah_powerLimit = MAX_RATE_POWER;
275 AH_PRIVATE(ah)->ah_tpScale = HAL_TP_SCALE_MAX; /* no scaling */
276
277 ahp->ah_antControl = HAL_ANT_VARIABLE;
278 ahp->ah_diversity = AH_TRUE;
279 ahp->ah_bIQCalibration = AH_FALSE;
280 /*
281 * Enable MIC handling.
282 */
283 ahp->ah_staId1Defaults = AR_STA_ID1_CRPT_MIC_ENABLE;
284 ahp->ah_rssiThr = INIT_RSSI_THR;
285 ahp->ah_tpcEnabled = AH_FALSE; /* disabled by default */
286 ahp->ah_phyPowerOn = AH_FALSE;
287 ahp->ah_macTPC = SM(MAX_RATE_POWER, AR_TPC_ACK)
288 | SM(MAX_RATE_POWER, AR_TPC_CTS)
289 | SM(MAX_RATE_POWER, AR_TPC_CHIRP);
290 ahp->ah_beaconInterval = 100; /* XXX [20..1000] */
291 ahp->ah_enable32kHzClock = DONT_USE_32KHZ;/* XXX */
292 ahp->ah_slottime = (u_int) -1;
293 ahp->ah_acktimeout = (u_int) -1;
294 ahp->ah_ctstimeout = (u_int) -1;
295 ahp->ah_sifstime = (u_int) -1;
296 OS_MEMCPY(&ahp->ah_bssidmask, defbssidmask, IEEE80211_ADDR_LEN);
297#undef N
298}
299
300/*
301 * Validate MAC version and revision.
302 */
303static HAL_BOOL
304ar5212IsMacSupported(uint8_t macVersion, uint8_t macRev)
305{
306#define N(a) (sizeof(a)/sizeof(a[0]))
307 static const struct {
308 uint8_t version;
309 uint8_t revMin, revMax;
310 } macs[] = {
311 { AR_SREV_VERSION_VENICE,
312 AR_SREV_D2PLUS, AR_SREV_REVISION_MAX },
313 { AR_SREV_VERSION_GRIFFIN,
314 AR_SREV_D2PLUS, AR_SREV_REVISION_MAX },
315 { AR_SREV_5413,
316 AR_SREV_REVISION_MIN, AR_SREV_REVISION_MAX },
317 { AR_SREV_5424,
318 AR_SREV_REVISION_MIN, AR_SREV_REVISION_MAX },
319 { AR_SREV_2425,
320 AR_SREV_REVISION_MIN, AR_SREV_REVISION_MAX },
321 { AR_SREV_2417,
322 AR_SREV_REVISION_MIN, AR_SREV_REVISION_MAX },
323 };
324 int i;
325
326 for (i = 0; i < N(macs); i++)
327 if (macs[i].version == macVersion &&
328 macs[i].revMin <= macRev && macRev <= macs[i].revMax)
329 return AH_TRUE;
330 return AH_FALSE;
331#undef N
332}
333
334/*
335 * Attach for an AR5212 part.
336 */
337struct ath_hal *
338ar5212Attach(uint16_t devid, HAL_SOFTC sc,
339 HAL_BUS_TAG st, HAL_BUS_HANDLE sh, HAL_STATUS *status)
340{
341#define AH_EEPROM_PROTECT(ah) \
342 (IS_PCIE(ah) ? AR_EEPROM_PROTECT_PCIE : AR_EEPROM_PROTECT)
343 struct ath_hal_5212 *ahp;
344 struct ath_hal *ah;
345 uint32_t val;
346 uint16_t eeval;
347 HAL_STATUS ecode;
348 HAL_BOOL rfStatus;
349
350 HALDEBUG(AH_NULL, HAL_DEBUG_ATTACH, "%s: sc %p st %p sh %p\n",
351 __func__, sc, (void*) st, (void*) sh);
352
353 /* NB: memory is returned zero'd */
354 ahp = ath_hal_malloc(sizeof (struct ath_hal_5212));
355 if (ahp == AH_NULL) {
356 HALDEBUG(AH_NULL, HAL_DEBUG_ANY,
357 "%s: cannot allocate memory for state block\n", __func__);
358 *status = HAL_ENOMEM;
359 return AH_NULL;
360 }
361 ar5212InitState(ahp, devid, sc, st, sh, status);
362 ah = &ahp->ah_priv.h;
363
364 if (!ar5212SetPowerMode(ah, HAL_PM_AWAKE, AH_TRUE)) {
365 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: couldn't wakeup chip\n",
366 __func__);
367 ecode = HAL_EIO;
368 goto bad;
369 }
370 /* Read Revisions from Chips before taking out of reset */
371 val = OS_REG_READ(ah, AR_SREV) & AR_SREV_ID;
372 AH_PRIVATE(ah)->ah_macVersion = val >> AR_SREV_ID_S;
373 AH_PRIVATE(ah)->ah_macRev = val & AR_SREV_REVISION;
374
375 if (!ar5212IsMacSupported(AH_PRIVATE(ah)->ah_macVersion, AH_PRIVATE(ah)->ah_macRev)) {
376 HALDEBUG(ah, HAL_DEBUG_ANY,
377 "%s: Mac Chip Rev 0x%02x.%x not supported\n" ,
378 __func__, AH_PRIVATE(ah)->ah_macVersion,
379 AH_PRIVATE(ah)->ah_macRev);
380 ecode = HAL_ENOTSUPP;
381 goto bad;
382 }
383
384 /* setup common ini data; rf backends handle remainder */
385 HAL_INI_INIT(&ahp->ah_ini_modes, ar5212Modes, 6);
386 HAL_INI_INIT(&ahp->ah_ini_common, ar5212Common, 2);
387
388 if (!ar5212ChipReset(ah, AH_NULL)) { /* reset chip */
389 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: chip reset failed\n", __func__);
390 ecode = HAL_EIO;
391 goto bad;
392 }
393
394 AH_PRIVATE(ah)->ah_phyRev = OS_REG_READ(ah, AR_PHY_CHIP_ID);
395
396 if (IS_PCIE(ah)) {
397 /* XXX: build flag to disable this? */
398 configurePciePowerSave(ah);
399 }
400
401 if (!ar5212ChipTest(ah)) {
402 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: hardware self-test failed\n",
403 __func__);
404 ecode = HAL_ESELFTEST;
405 goto bad;
406 }
407
408 /* Enable PCI core retry fix in software for Hainan and up */
409 if (AH_PRIVATE(ah)->ah_macVersion >= AR_SREV_VERSION_VENICE)
410 OS_REG_SET_BIT(ah, AR_PCICFG, AR_PCICFG_RETRYFIXEN);
411
412 /*
413 * Set correct Baseband to analog shift
414 * setting to access analog chips.
415 */
416 OS_REG_WRITE(ah, AR_PHY(0), 0x00000007);
417
418 /* Read Radio Chip Rev Extract */
419 AH_PRIVATE(ah)->ah_analog5GhzRev = ar5212GetRadioRev(ah);
420 /* NB: silently accept anything in release code per Atheros */
421 switch (AH_PRIVATE(ah)->ah_analog5GhzRev & AR_RADIO_SREV_MAJOR) {
422 case AR_RAD5111_SREV_MAJOR:
423 case AR_RAD5112_SREV_MAJOR:
424 case AR_RAD2112_SREV_MAJOR:
425 case AR_RAD2111_SREV_MAJOR:
426 case AR_RAD2413_SREV_MAJOR:
427 case AR_RAD5413_SREV_MAJOR:
428 case AR_RAD5424_SREV_MAJOR:
429 break;
430 default:
431 if (AH_PRIVATE(ah)->ah_analog5GhzRev == 0) {
432 /*
433 * When RF_Silent is used, the
434 * analog chip is reset. So when the system boots
435 * up with the radio switch off we cannot determine
436 * the RF chip rev. To workaround this check the
437 * mac+phy revs and if Hainan, set the radio rev
438 * to Derby.
439 */
440 if (AH_PRIVATE(ah)->ah_macVersion == AR_SREV_VERSION_VENICE &&
441 AH_PRIVATE(ah)->ah_macRev == AR_SREV_HAINAN &&
442 AH_PRIVATE(ah)->ah_phyRev == AR_PHYREV_HAINAN) {
443 AH_PRIVATE(ah)->ah_analog5GhzRev = AR_ANALOG5REV_HAINAN;
444 break;
445 }
446 if (IS_2413(ah)) { /* Griffin */
447 AH_PRIVATE(ah)->ah_analog5GhzRev =
448 AR_RAD2413_SREV_MAJOR | 0x1;
449 break;
450 }
451 if (IS_5413(ah)) { /* Eagle */
452 AH_PRIVATE(ah)->ah_analog5GhzRev =
453 AR_RAD5413_SREV_MAJOR | 0x2;
454 break;
455 }
456 if (IS_2425(ah) || IS_2417(ah)) {/* Swan or Nala */
457 AH_PRIVATE(ah)->ah_analog5GhzRev =
458 AR_RAD5424_SREV_MAJOR | 0x2;
459 break;
460 }
461 }
462#ifdef AH_DEBUG
463 HALDEBUG(ah, HAL_DEBUG_ANY,
464 "%s: 5G Radio Chip Rev 0x%02X is not supported by "
465 "this driver\n",
466 __func__, AH_PRIVATE(ah)->ah_analog5GhzRev);
467 ecode = HAL_ENOTSUPP;
468 goto bad;
469#endif
470 }
471 if (IS_RAD5112_REV1(ah)) {
472 HALDEBUG(ah, HAL_DEBUG_ANY,
473 "%s: 5112 Rev 1 is not supported by this "
474 "driver (analog5GhzRev 0x%x)\n", __func__,
475 AH_PRIVATE(ah)->ah_analog5GhzRev);
476 ecode = HAL_ENOTSUPP;
477 goto bad;
478 }
479
480 val = OS_REG_READ(ah, AR_PCICFG);
481 val = MS(val, AR_PCICFG_EEPROM_SIZE);
482 if (val == 0) {
483 if (!IS_PCIE(ah)) {
484 HALDEBUG(ah, HAL_DEBUG_ANY,
485 "%s: unsupported EEPROM size %u (0x%x) found\n",
486 __func__, val, val);
487 ecode = HAL_EESIZE;
488 goto bad;
489 }
490 /* XXX AH_PRIVATE(ah)->ah_isPciExpress = AH_TRUE; */
491 } else if (val != AR_PCICFG_EEPROM_SIZE_16K) {
492 if (AR_PCICFG_EEPROM_SIZE_FAILED == val) {
493 HALDEBUG(ah, HAL_DEBUG_ANY,
494 "%s: unsupported EEPROM size %u (0x%x) found\n",
495 __func__, val, val);
496 ecode = HAL_EESIZE;
497 goto bad;
498 }
499 HALDEBUG(ah, HAL_DEBUG_ANY,
500 "%s: EEPROM size = %d. Must be %d (16k).\n",
501 __func__, val, AR_PCICFG_EEPROM_SIZE_16K);
502 ecode = HAL_EESIZE;
503 goto bad;
504 }
505 ecode = ath_hal_legacyEepromAttach(ah);
506 if (ecode != HAL_OK) {
507 goto bad;
508 }
509 ahp->ah_isHb63 = IS_2425(ah) && ath_hal_eepromGetFlag(ah, AR_EEP_ISTALON);
510
511 /*
512 * If Bmode and AR5212, verify 2.4 analog exists
513 */
514 if (ath_hal_eepromGetFlag(ah, AR_EEP_BMODE) &&
515 (AH_PRIVATE(ah)->ah_analog5GhzRev & 0xF0) == AR_RAD5111_SREV_MAJOR) {
516 /*
517 * Set correct Baseband to analog shift
518 * setting to access analog chips.
519 */
520 OS_REG_WRITE(ah, AR_PHY(0), 0x00004007);
521 OS_DELAY(2000);
522 AH_PRIVATE(ah)->ah_analog2GhzRev = ar5212GetRadioRev(ah);
523
524 /* Set baseband for 5GHz chip */
525 OS_REG_WRITE(ah, AR_PHY(0), 0x00000007);
526 OS_DELAY(2000);
527 if ((AH_PRIVATE(ah)->ah_analog2GhzRev & 0xF0) != AR_RAD2111_SREV_MAJOR) {
528 HALDEBUG(ah, HAL_DEBUG_ANY,
529 "%s: 2G Radio Chip Rev 0x%02X is not "
530 "supported by this driver\n", __func__,
531 AH_PRIVATE(ah)->ah_analog2GhzRev);
532 ecode = HAL_ENOTSUPP;
533 goto bad;
534 }
535 }
536
537 ecode = ath_hal_eepromGet(ah, AR_EEP_REGDMN_0, &eeval);
538 if (ecode != HAL_OK) {
539 HALDEBUG(ah, HAL_DEBUG_ANY,
540 "%s: cannot read regulatory domain from EEPROM\n",
541 __func__);
542 goto bad;
543 }
544 AH_PRIVATE(ah)->ah_currentRD = eeval;
545 /* XXX record serial number */
546
547 /*
548 * Got everything we need now to setup the capabilities.
549 */
550 if (!ar5212FillCapabilityInfo(ah)) {
551 HALDEBUG(ah, HAL_DEBUG_ANY,
552 "%s: failed ar5212FillCapabilityInfo\n", __func__);
553 ecode = HAL_EEREAD;
554 goto bad;
555 }
556
557 rfStatus = AH_FALSE;
558 if (IS_5413(ah)) {
559#ifdef AH_SUPPORT_5413
560 rfStatus = ar5413RfAttach(ah, &ecode);
561#else
562 ecode = HAL_ENOTSUPP;
563#endif
564 }
565 else if (IS_2413(ah))
566#ifdef AH_SUPPORT_2413
567 rfStatus = ar2413RfAttach(ah, &ecode);
568#else
569 ecode = HAL_ENOTSUPP;
570#endif
571 else if (IS_RAD5112(ah))
572#ifdef AH_SUPPORT_5112
573 rfStatus = ar5112RfAttach(ah, &ecode);
574#else
575 ecode = HAL_ENOTSUPP;
576#endif
577 else if (IS_2425(ah) || IS_2417(ah))
578#ifdef AH_SUPPORT_2425
579 rfStatus = ar2425RfAttach(ah, &ecode);
580#else
581 ecode = HAL_ENOTSUPP;
582#endif
583 else if (IS_RAD5111(ah))
584#ifdef AH_SUPPORT_5111
585 rfStatus = ar5111RfAttach(ah, &ecode);
586#else
587 ecode = HAL_ENOTSUPP;
588#endif
589 if (!rfStatus) {
590 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: RF setup failed, status %u\n",
591 __func__, ecode);
592 goto bad;
593 }
594 /*
595 * Set noise floor adjust method; we arrange a
596 * direct call instead of thunking.
597 */
598 AH_PRIVATE(ah)->ah_getNfAdjust = ahp->ah_rfHal->getNfAdjust;
599
600 /* Initialize gain ladder thermal calibration structure */
601 ar5212InitializeGainValues(ah);
602
603 ecode = ath_hal_eepromGet(ah, AR_EEP_MACADDR, ahp->ah_macaddr);
604 if (ecode != HAL_OK) {
605 HALDEBUG(ah, HAL_DEBUG_ANY,
606 "%s: error getting mac address from EEPROM\n", __func__);
607 goto bad;
608 }
609
610 ar5212AniSetup(ah);
611 /* Setup of Radar/AR structures happens in ath_hal_initchannels*/
612 ar5212InitNfCalHistBuffer(ah);
613
614 /* XXX EAR stuff goes here */
615
616 HALDEBUG(ah, HAL_DEBUG_ATTACH, "%s: return\n", __func__);
617
618 return ah;
619
620bad:
621 if (ahp)
622 ar5212Detach((struct ath_hal *) ahp);
623 if (status)
624 *status = ecode;
625 return AH_NULL;
626#undef AH_EEPROM_PROTECT
627}
628
629void
630ar5212Detach(struct ath_hal *ah)
631{
632 HALDEBUG(ah, HAL_DEBUG_ATTACH, "%s:\n", __func__);
633
634 HALASSERT(ah != AH_NULL);
635 HALASSERT(ah->ah_magic == AR5212_MAGIC);
636
637 ar5212AniDetach(ah);
638 ar5212RfDetach(ah);
639 ar5212Disable(ah);
640 ar5212SetPowerMode(ah, HAL_PM_FULL_SLEEP, AH_TRUE);
641
642 ath_hal_eepromDetach(ah);
643 ath_hal_free(ah);
644}
645
646HAL_BOOL
647ar5212ChipTest(struct ath_hal *ah)
648{
649 uint32_t regAddr[2] = { AR_STA_ID0, AR_PHY_BASE+(8 << 2) };
650 uint32_t regHold[2];
651 uint32_t patternData[4] =
652 { 0x55555555, 0xaaaaaaaa, 0x66666666, 0x99999999 };
653 int i, j;
654
655 /* Test PHY & MAC registers */
656 for (i = 0; i < 2; i++) {
657 uint32_t addr = regAddr[i];
658 uint32_t wrData, rdData;
659
660 regHold[i] = OS_REG_READ(ah, addr);
661 for (j = 0; j < 0x100; j++) {
662 wrData = (j << 16) | j;
663 OS_REG_WRITE(ah, addr, wrData);
664 rdData = OS_REG_READ(ah, addr);
665 if (rdData != wrData) {
666 HALDEBUG(ah, HAL_DEBUG_ANY,
667"%s: address test failed addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
668 __func__, addr, wrData, rdData);
669 return AH_FALSE;
670 }
671 }
672 for (j = 0; j < 4; j++) {
673 wrData = patternData[j];
674 OS_REG_WRITE(ah, addr, wrData);
675 rdData = OS_REG_READ(ah, addr);
676 if (wrData != rdData) {
677 HALDEBUG(ah, HAL_DEBUG_ANY,
678"%s: address test failed addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
679 __func__, addr, wrData, rdData);
680 return AH_FALSE;
681 }
682 }
683 OS_REG_WRITE(ah, regAddr[i], regHold[i]);
684 }
685 OS_DELAY(100);
686 return AH_TRUE;
687}
688
689/*
690 * Store the channel edges for the requested operational mode
691 */
692HAL_BOOL
693ar5212GetChannelEdges(struct ath_hal *ah,
694 uint16_t flags, uint16_t *low, uint16_t *high)
695{
696 if (flags & CHANNEL_5GHZ) {
697 *low = 4915;
698 *high = 6100;
699 return AH_TRUE;
700 }
701 if ((flags & CHANNEL_2GHZ) &&
702 (ath_hal_eepromGetFlag(ah, AR_EEP_BMODE) ||
703 ath_hal_eepromGetFlag(ah, AR_EEP_GMODE))) {
704 *low = 2312;
705 *high = 2732;
706 return AH_TRUE;
707 }
708 return AH_FALSE;
709}
710
711/*
712 * Fill all software cached or static hardware state information.
713 * Return failure if capabilities are to come from EEPROM and
714 * cannot be read.
715 */
716HAL_BOOL
717ar5212FillCapabilityInfo(struct ath_hal *ah)
718{
719#define AR_KEYTABLE_SIZE 128
720#define IS_GRIFFIN_LITE(ah) \
721 (AH_PRIVATE(ah)->ah_macVersion == AR_SREV_VERSION_GRIFFIN && \
722 AH_PRIVATE(ah)->ah_macRev == AR_SREV_GRIFFIN_LITE)
723#define IS_COBRA(ah) \
724 (AH_PRIVATE(ah)->ah_macVersion == AR_SREV_VERSION_COBRA)
725#define IS_2112(ah) \
726 ((AH_PRIVATE(ah)->ah_analog5GhzRev & 0xF0) == AR_RAD2112_SREV_MAJOR)
727
728 struct ath_hal_private *ahpriv = AH_PRIVATE(ah);
729 HAL_CAPABILITIES *pCap = &ahpriv->ah_caps;
730 uint16_t capField, val;
731
732 /* Read the capability EEPROM location */
733 if (ath_hal_eepromGet(ah, AR_EEP_OPCAP, &capField) != HAL_OK) {
734 HALDEBUG(ah, HAL_DEBUG_ANY,
735 "%s: unable to read caps from eeprom\n", __func__);
736 return AH_FALSE;
737 }
738 if (IS_2112(ah))
739 ath_hal_eepromSet(ah, AR_EEP_AMODE, AH_FALSE);
740 if (capField == 0 && IS_GRIFFIN_LITE(ah)) {
741 /*
742 * For griffin-lite cards with unprogrammed capabilities.
743 */
744 ath_hal_eepromSet(ah, AR_EEP_COMPRESS, AH_FALSE);
745 ath_hal_eepromSet(ah, AR_EEP_FASTFRAME, AH_FALSE);
746 ath_hal_eepromSet(ah, AR_EEP_TURBO5DISABLE, AH_TRUE);
747 ath_hal_eepromSet(ah, AR_EEP_TURBO2DISABLE, AH_TRUE);
748 HALDEBUG(ah, HAL_DEBUG_ATTACH,
749 "%s: override caps for griffin-lite, now 0x%x (+!turbo)\n",
750 __func__, capField);
751 }
752
753 /* Modify reg domain on newer cards that need to work with older sw */
754 if (ahpriv->ah_opmode != HAL_M_HOSTAP &&
755 ahpriv->ah_subvendorid == AR_SUBVENDOR_ID_NEW_A) {
756 if (ahpriv->ah_currentRD == 0x64 ||
757 ahpriv->ah_currentRD == 0x65)
758 ahpriv->ah_currentRD += 5;
759 else if (ahpriv->ah_currentRD == 0x41)
760 ahpriv->ah_currentRD = 0x43;
761 HALDEBUG(ah, HAL_DEBUG_ATTACH, "%s: regdomain mapped to 0x%x\n",
762 __func__, ahpriv->ah_currentRD);
763 }
764
765 if (AH_PRIVATE(ah)->ah_macVersion == AR_SREV_2417 ||
766 AH_PRIVATE(ah)->ah_macVersion == AR_SREV_2425) {
767 HALDEBUG(ah, HAL_DEBUG_ATTACH,
768 "%s: enable Bmode and disable turbo for Swan/Nala\n",
769 __func__);
770 ath_hal_eepromSet(ah, AR_EEP_BMODE, AH_TRUE);
771 ath_hal_eepromSet(ah, AR_EEP_COMPRESS, AH_FALSE);
772 ath_hal_eepromSet(ah, AR_EEP_FASTFRAME, AH_FALSE);
773 ath_hal_eepromSet(ah, AR_EEP_TURBO5DISABLE, AH_TRUE);
774 ath_hal_eepromSet(ah, AR_EEP_TURBO2DISABLE, AH_TRUE);
775 }
776
777 /* Construct wireless mode from EEPROM */
778 pCap->halWirelessModes = 0;
779 if (ath_hal_eepromGetFlag(ah, AR_EEP_AMODE)) {
780 pCap->halWirelessModes |= HAL_MODE_11A;
781 if (!ath_hal_eepromGetFlag(ah, AR_EEP_TURBO5DISABLE))
782 pCap->halWirelessModes |= HAL_MODE_TURBO;
783 }
784 if (ath_hal_eepromGetFlag(ah, AR_EEP_BMODE))
785 pCap->halWirelessModes |= HAL_MODE_11B;
786 if (ath_hal_eepromGetFlag(ah, AR_EEP_GMODE) &&
787 ahpriv->ah_subvendorid != AR_SUBVENDOR_ID_NOG) {
788 pCap->halWirelessModes |= HAL_MODE_11G;
789 if (!ath_hal_eepromGetFlag(ah, AR_EEP_TURBO2DISABLE))
790 pCap->halWirelessModes |= HAL_MODE_108G;
791 }
792
793 pCap->halLow2GhzChan = 2312;
794 /* XXX 2417 too? */
795 if (IS_RAD5112_ANY(ah) || IS_5413(ah) || IS_2425(ah) || IS_2417(ah))
796 pCap->halHigh2GhzChan = 2500;
797 else
798 pCap->halHigh2GhzChan = 2732;
799
800 pCap->halLow5GhzChan = 4915;
801 pCap->halHigh5GhzChan = 6100;
802
803 pCap->halCipherCkipSupport = AH_FALSE;
804 pCap->halCipherTkipSupport = AH_TRUE;
805 pCap->halCipherAesCcmSupport =
806 (ath_hal_eepromGetFlag(ah, AR_EEP_AES) &&
807 ((AH_PRIVATE(ah)->ah_macVersion > AR_SREV_VERSION_VENICE) ||
808 ((AH_PRIVATE(ah)->ah_macVersion == AR_SREV_VERSION_VENICE) &&
809 (AH_PRIVATE(ah)->ah_macRev >= AR_SREV_VERSION_OAHU))));
810
811 pCap->halMicCkipSupport = AH_FALSE;
812 pCap->halMicTkipSupport = AH_TRUE;
813 pCap->halMicAesCcmSupport = ath_hal_eepromGetFlag(ah, AR_EEP_AES);
814 /*
815 * Starting with Griffin TX+RX mic keys can be combined
816 * in one key cache slot.
817 */
818 if (AH_PRIVATE(ah)->ah_macVersion >= AR_SREV_VERSION_GRIFFIN)
819 pCap->halTkipMicTxRxKeySupport = AH_TRUE;
820 else
821 pCap->halTkipMicTxRxKeySupport = AH_FALSE;
822 pCap->halChanSpreadSupport = AH_TRUE;
823 pCap->halSleepAfterBeaconBroken = AH_TRUE;
824
825 if (ahpriv->ah_macRev > 1 || IS_COBRA(ah)) {
826 pCap->halCompressSupport =
827 ath_hal_eepromGetFlag(ah, AR_EEP_COMPRESS) &&
828 (pCap->halWirelessModes & (HAL_MODE_11A|HAL_MODE_11G)) != 0;
829 pCap->halBurstSupport = ath_hal_eepromGetFlag(ah, AR_EEP_BURST);
830 pCap->halFastFramesSupport =
831 ath_hal_eepromGetFlag(ah, AR_EEP_FASTFRAME) &&
832 (pCap->halWirelessModes & (HAL_MODE_11A|HAL_MODE_11G)) != 0;
833 pCap->halChapTuningSupport = AH_TRUE;
834 pCap->halTurboPrimeSupport = AH_TRUE;
835 }
836 pCap->halTurboGSupport = pCap->halWirelessModes & HAL_MODE_108G;
837
838 pCap->halPSPollBroken = AH_TRUE; /* XXX fixed in later revs? */
839 pCap->halVEOLSupport = AH_TRUE;
840 pCap->halBssIdMaskSupport = AH_TRUE;
841 pCap->halMcastKeySrchSupport = AH_TRUE;
842 if ((ahpriv->ah_macVersion == AR_SREV_VERSION_VENICE &&
843 ahpriv->ah_macRev == 8) ||
844 ahpriv->ah_macVersion > AR_SREV_VERSION_VENICE)
845 pCap->halTsfAddSupport = AH_TRUE;
846
847 if (ath_hal_eepromGet(ah, AR_EEP_MAXQCU, &val) == HAL_OK)
848 pCap->halTotalQueues = val;
849 else
850 pCap->halTotalQueues = HAL_NUM_TX_QUEUES;
851
852 if (ath_hal_eepromGet(ah, AR_EEP_KCENTRIES, &val) == HAL_OK)
853 pCap->halKeyCacheSize = val;
854 else
855 pCap->halKeyCacheSize = AR_KEYTABLE_SIZE;
856
857 pCap->halChanHalfRate = AH_TRUE;
858 pCap->halChanQuarterRate = AH_TRUE;
859
860 if (ath_hal_eepromGetFlag(ah, AR_EEP_RFKILL) &&
861 ath_hal_eepromGet(ah, AR_EEP_RFSILENT, &ahpriv->ah_rfsilent) == HAL_OK) {
862 /* NB: enabled by default */
863 ahpriv->ah_rfkillEnabled = AH_TRUE;
864 pCap->halRfSilentSupport = AH_TRUE;
865 }
866
867 /* NB: this is a guess, noone seems to know the answer */
868 ahpriv->ah_rxornIsFatal =
869 (AH_PRIVATE(ah)->ah_macVersion < AR_SREV_VERSION_VENICE);
870
871 /* h/w phy counters first appeared in Hainan */
872 pCap->halHwPhyCounterSupport =
873 (AH_PRIVATE(ah)->ah_macVersion == AR_SREV_VERSION_VENICE &&
874 AH_PRIVATE(ah)->ah_macRev == AR_SREV_HAINAN) ||
875 AH_PRIVATE(ah)->ah_macVersion > AR_SREV_VERSION_VENICE;
876
877 pCap->halTstampPrecision = 15;
878
879 return AH_TRUE;
880#undef IS_COBRA
881#undef IS_GRIFFIN_LITE
882#undef AR_KEYTABLE_SIZE
883}
884#endif /* AH_SUPPORT_AR5212 */