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: ar5416_attach.c,v 1.27 2008/11/27 22:30:07 sam Exp $
18 */
19#include "opt_ah.h"
20
21#ifdef AH_SUPPORT_AR5416
22
23#if !defined(AH_SUPPORT_2133)
24#error "No 5416 RF support defined"
25#endif
26
27#include "ah.h"
28#include "ah_internal.h"
29#include "ah_devid.h"
30
31#include "ar5416/ar5416.h"
32#include "ar5416/ar5416reg.h"
33#include "ar5416/ar5416phy.h"
34
35#include "ar5416/ar5416.ini"
36
37static void
38ar5416AniSetup(struct ath_hal *ah)
39{
40 static const struct ar5212AniParams aniparams = {
41 .maxNoiseImmunityLevel = 4, /* levels 0..4 */
42 .totalSizeDesired = { -55, -55, -55, -55, -62 },
43 .coarseHigh = { -14, -14, -14, -14, -12 },
44 .coarseLow = { -64, -64, -64, -64, -70 },
45 .firpwr = { -78, -78, -78, -78, -80 },
46 .maxSpurImmunityLevel = 2,
47 .cycPwrThr1 = { 2, 4, 6 },
48 .maxFirstepLevel = 2, /* levels 0..2 */
49 .firstep = { 0, 4, 8 },
50 .ofdmTrigHigh = 500,
51 .ofdmTrigLow = 200,
52 .cckTrigHigh = 200,
53 .cckTrigLow = 100,
54 .rssiThrHigh = 40,
55 .rssiThrLow = 7,
56 .period = 100,
57 };
58 /* NB: ANI is not enabled yet */
59 ar5212AniAttach(ah, &aniparams, &aniparams, AH_FALSE);
60}
61
62/*
63 * Attach for an AR5416 part.
64 */
65void
66ar5416InitState(struct ath_hal_5416 *ahp5416, uint16_t devid, HAL_SOFTC sc,
67 HAL_BUS_TAG st, HAL_BUS_HANDLE sh, HAL_STATUS *status)
68{
69 struct ath_hal_5212 *ahp;
70 struct ath_hal *ah;
71
72 ahp = &ahp5416->ah_5212;
73 ar5212InitState(ahp, devid, sc, st, sh, status);
74 ah = &ahp->ah_priv.h;
75
76 /* override 5212 methods for our needs */
77 ah->ah_magic = AR5416_MAGIC;
78 ah->ah_getRateTable = ar5416GetRateTable;
79 ah->ah_detach = ar5416Detach;
80
81 /* Reset functions */
82 ah->ah_reset = ar5416Reset;
83 ah->ah_phyDisable = ar5416PhyDisable;
84 ah->ah_disable = ar5416Disable;
85 ah->ah_perCalibration = ar5416PerCalibration;
86 ah->ah_perCalibrationN = ar5416PerCalibrationN,
87 ah->ah_resetCalValid = ar5416ResetCalValid,
88 ah->ah_setTxPowerLimit = ar5416SetTxPowerLimit;
89
90 /* Transmit functions */
91 ah->ah_stopTxDma = ar5416StopTxDma;
92 ah->ah_setupTxDesc = ar5416SetupTxDesc;
93 ah->ah_setupXTxDesc = ar5416SetupXTxDesc;
94 ah->ah_fillTxDesc = ar5416FillTxDesc;
95 ah->ah_procTxDesc = ar5416ProcTxDesc;
96
97 /* Receive Functions */
98 ah->ah_startPcuReceive = ar5416StartPcuReceive;
99 ah->ah_stopPcuReceive = ar5416StopPcuReceive;
100 ah->ah_setupRxDesc = ar5416SetupRxDesc;
101 ah->ah_procRxDesc = ar5416ProcRxDesc;
102 ah->ah_rxMonitor = ar5416AniPoll,
103 ah->ah_procMibEvent = ar5416ProcessMibIntr,
104
105 /* Misc Functions */
106 ah->ah_getDiagState = ar5416GetDiagState;
107 ah->ah_setLedState = ar5416SetLedState;
108 ah->ah_gpioCfgOutput = ar5416GpioCfgOutput;
109 ah->ah_gpioCfgInput = ar5416GpioCfgInput;
110 ah->ah_gpioGet = ar5416GpioGet;
111 ah->ah_gpioSet = ar5416GpioSet;
112 ah->ah_gpioSetIntr = ar5416GpioSetIntr;
113 ah->ah_resetTsf = ar5416ResetTsf;
114 ah->ah_getRfGain = ar5416GetRfgain;
115 ah->ah_setAntennaSwitch = ar5416SetAntennaSwitch;
116 ah->ah_setDecompMask = ar5416SetDecompMask;
117 ah->ah_setCoverageClass = ar5416SetCoverageClass;
118
119 ah->ah_resetKeyCacheEntry = ar5416ResetKeyCacheEntry;
120 ah->ah_setKeyCacheEntry = ar5416SetKeyCacheEntry;
121
122 /* Power Management Functions */
123 ah->ah_setPowerMode = ar5416SetPowerMode;
124
125 /* Beacon Management Functions */
126 ah->ah_setBeaconTimers = ar5416SetBeaconTimers;
127 ah->ah_beaconInit = ar5416BeaconInit;
128 ah->ah_setStationBeaconTimers = ar5416SetStaBeaconTimers;
129 ah->ah_resetStationBeaconTimers = ar5416ResetStaBeaconTimers;
130
131 /* XXX 802.11n Functions */
132#if 0
133 ah->ah_chainTxDesc = ar5416ChainTxDesc;
134 ah->ah_setupFirstTxDesc = ar5416SetupFirstTxDesc;
135 ah->ah_setupLastTxDesc = ar5416SetupLastTxDesc;
136 ah->ah_set11nRateScenario = ar5416Set11nRateScenario;
137 ah->ah_set11nAggrMiddle = ar5416Set11nAggrMiddle;
138 ah->ah_clr11nAggr = ar5416Clr11nAggr;
139 ah->ah_set11nBurstDuration = ar5416Set11nBurstDuration;
140 ah->ah_get11nExtBusy = ar5416Get11nExtBusy;
141 ah->ah_set11nMac2040 = ar5416Set11nMac2040;
142 ah->ah_get11nRxClear = ar5416Get11nRxClear;
143 ah->ah_set11nRxClear = ar5416Set11nRxClear;
144#endif
145
146 /* Interrupt functions */
147 ah->ah_isInterruptPending = ar5416IsInterruptPending;
148 ah->ah_getPendingInterrupts = ar5416GetPendingInterrupts;
149 ah->ah_setInterrupts = ar5416SetInterrupts;
150
151 ahp->ah_priv.ah_getWirelessModes= ar5416GetWirelessModes;
152 ahp->ah_priv.ah_eepromRead = ar5416EepromRead;
153#ifdef AH_SUPPORT_WRITE_EEPROM
154 ahp->ah_priv.ah_eepromWrite = ar5416EepromWrite;
155#endif
156 ahp->ah_priv.ah_gpioCfgOutput = ar5416GpioCfgOutput;
157 ahp->ah_priv.ah_gpioCfgInput = ar5416GpioCfgInput;
158 ahp->ah_priv.ah_gpioGet = ar5416GpioGet;
159 ahp->ah_priv.ah_gpioSet = ar5416GpioSet;
160 ahp->ah_priv.ah_gpioSetIntr = ar5416GpioSetIntr;
161 ahp->ah_priv.ah_getChipPowerLimits = ar5416GetChipPowerLimits;
162
163 /*
164 * Start by setting all Owl devices to 2x2
165 */
166 AH5416(ah)->ah_rx_chainmask = AR5416_DEFAULT_RXCHAINMASK;
167 AH5416(ah)->ah_tx_chainmask = AR5416_DEFAULT_TXCHAINMASK;
168}
169
170/*
171 * Attach for an AR5416 part.
172 */
173struct ath_hal *
174ar5416Attach(uint16_t devid, HAL_SOFTC sc,
175 HAL_BUS_TAG st, HAL_BUS_HANDLE sh, HAL_STATUS *status)
176{
177 struct ath_hal_5416 *ahp5416;
178 struct ath_hal_5212 *ahp;
179 struct ath_hal *ah;
180 uint32_t val;
181 HAL_STATUS ecode;
182 HAL_BOOL rfStatus;
183
184 HALDEBUG(AH_NULL, HAL_DEBUG_ATTACH, "%s: sc %p st %p sh %p\n",
185 __func__, sc, (void*) st, (void*) sh);
186
187 /* NB: memory is returned zero'd */
188 ahp5416 = ath_hal_malloc(sizeof (struct ath_hal_5416) +
189 /* extra space for Owl 2.1/2.2 WAR */
190 sizeof(ar5416Addac)
191 );
192 if (ahp5416 == AH_NULL) {
193 HALDEBUG(AH_NULL, HAL_DEBUG_ANY,
194 "%s: cannot allocate memory for state block\n", __func__);
195 *status = HAL_ENOMEM;
196 return AH_NULL;
197 }
198 ar5416InitState(ahp5416, devid, sc, st, sh, status);
199 ahp = &ahp5416->ah_5212;
200 ah = &ahp->ah_priv.h;
201
202 if (!ar5416SetResetReg(ah, HAL_RESET_POWER_ON)) {
203 /* reset chip */
204 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: couldn't reset chip\n", __func__);
205 ecode = HAL_EIO;
206 goto bad;
207 }
208
209 if (!ar5416SetPowerMode(ah, HAL_PM_AWAKE, AH_TRUE)) {
210 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: couldn't wakeup chip\n", __func__);
211 ecode = HAL_EIO;
212 goto bad;
213 }
214 /* Read Revisions from Chips before taking out of reset */
215 val = OS_REG_READ(ah, AR_SREV) & AR_SREV_ID;
216 AH_PRIVATE(ah)->ah_macVersion = val >> AR_SREV_ID_S;
217 AH_PRIVATE(ah)->ah_macRev = val & AR_SREV_REVISION;
218
219 /* setup common ini data; rf backends handle remainder */
220 HAL_INI_INIT(&ahp->ah_ini_modes, ar5416Modes, 6);
221 HAL_INI_INIT(&ahp->ah_ini_common, ar5416Common, 2);
222
223 HAL_INI_INIT(&AH5416(ah)->ah_ini_bb_rfgain, ar5416BB_RfGain, 3);
224 HAL_INI_INIT(&AH5416(ah)->ah_ini_bank0, ar5416Bank0, 2);
225 HAL_INI_INIT(&AH5416(ah)->ah_ini_bank1, ar5416Bank1, 2);
226 HAL_INI_INIT(&AH5416(ah)->ah_ini_bank2, ar5416Bank2, 2);
227 HAL_INI_INIT(&AH5416(ah)->ah_ini_bank3, ar5416Bank3, 3);
228 HAL_INI_INIT(&AH5416(ah)->ah_ini_bank6, ar5416Bank6, 3);
229 HAL_INI_INIT(&AH5416(ah)->ah_ini_bank7, ar5416Bank7, 2);
230 HAL_INI_INIT(&AH5416(ah)->ah_ini_addac, ar5416Addac, 2);
231
232 if (!IS_5416V2_2(ah)) { /* Owl 2.1/2.0 */
233 struct ini {
234 uint32_t *data; /* NB: !const */
235 int rows, cols;
236 };
237 /* override CLKDRV value */
238 OS_MEMCPY(&AH5416(ah)[1], ar5416Addac, sizeof(ar5416Addac));
239 AH5416(ah)->ah_ini_addac.data = (uint32_t *) &AH5416(ah)[1];
240 HAL_INI_VAL((struct ini *)&AH5416(ah)->ah_ini_addac, 31, 1) = 0;
241 }
242
243 if (!ar5416ChipReset(ah, AH_NULL)) { /* reset chip */
244 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: chip reset failed\n",
245 __func__);
246 ecode = HAL_EIO;
247 goto bad;
248 }
249
250 AH_PRIVATE(ah)->ah_phyRev = OS_REG_READ(ah, AR_PHY_CHIP_ID);
251
252 if (!ar5212ChipTest(ah)) {
253 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: hardware self-test failed\n",
254 __func__);
255 ecode = HAL_ESELFTEST;
256 goto bad;
257 }
258
259 /*
260 * Set correct Baseband to analog shift
261 * setting to access analog chips.
262 */
263 OS_REG_WRITE(ah, AR_PHY(0), 0x00000007);
264
265 /* Read Radio Chip Rev Extract */
266 AH_PRIVATE(ah)->ah_analog5GhzRev = ar5212GetRadioRev(ah);
267 switch (AH_PRIVATE(ah)->ah_analog5GhzRev & AR_RADIO_SREV_MAJOR) {
268 case AR_RAD5122_SREV_MAJOR: /* Fowl: 5G/2x2 */
269 case AR_RAD2122_SREV_MAJOR: /* Fowl: 2+5G/2x2 */
270 case AR_RAD2133_SREV_MAJOR: /* Fowl: 2G/3x3 */
271 case AR_RAD5133_SREV_MAJOR: /* Fowl: 2+5G/3x3 */
272 break;
273 default:
274 if (AH_PRIVATE(ah)->ah_analog5GhzRev == 0) {
275 /*
276 * When RF_Silen is used the analog chip is reset.
277 * So when the system boots with radio switch off
278 * the RF chip rev reads back as zero and we need
279 * to use the mac+phy revs to set the radio rev.
280 */
281 AH_PRIVATE(ah)->ah_analog5GhzRev =
282 AR_RAD5133_SREV_MAJOR;
283 break;
284 }
285 /* NB: silently accept anything in release code per Atheros */
286#ifdef AH_DEBUG
287 HALDEBUG(ah, HAL_DEBUG_ANY,
288 "%s: 5G Radio Chip Rev 0x%02X is not supported by "
289 "this driver\n", __func__,
290 AH_PRIVATE(ah)->ah_analog5GhzRev);
291 ecode = HAL_ENOTSUPP;
292 goto bad;
293#endif
294 }
295
296 ecode = ath_hal_v14EepromAttach(ah);
297 if (ecode != HAL_OK)
298 goto bad;
299
300 /*
301 * Got everything we need now to setup the capabilities.
302 */
303 if (!ar5416FillCapabilityInfo(ah)) {
304 ecode = HAL_EEREAD;
305 goto bad;
306 }
307
308 ecode = ath_hal_eepromGet(ah, AR_EEP_MACADDR, ahp->ah_macaddr);
309 if (ecode != HAL_OK) {
310 HALDEBUG(ah, HAL_DEBUG_ANY,
311 "%s: error getting mac address from EEPROM\n", __func__);
312 goto bad;
313 }
314 /* XXX How about the serial number ? */
315 /* Read Reg Domain */
316 AH_PRIVATE(ah)->ah_currentRD =
317 ath_hal_eepromGet(ah, AR_EEP_REGDMN_0, AH_NULL);
318
319 /*
320 * ah_miscMode is populated by ar5416FillCapabilityInfo()
321 * starting from griffin. Set here to make sure that
322 * AR_MISC_MODE_MIC_NEW_LOC_ENABLE is set before a GTK is
323 * placed into hardware.
324 */
325 if (ahp->ah_miscMode != 0)
326 OS_REG_WRITE(ah, AR_MISC_MODE, ahp->ah_miscMode);
327
328 HALDEBUG(ah, HAL_DEBUG_ATTACH, "%s: Attaching AR2133 radio\n",
329 __func__);
330 rfStatus = ar2133RfAttach(ah, &ecode);
331 if (!rfStatus) {
332 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: RF setup failed, status %u\n",
333 __func__, ecode);
334 goto bad;
335 }
336
337 ar5416AniSetup(ah); /* Anti Noise Immunity */
338 ar5416InitNfHistBuff(AH5416(ah)->ah_cal.nfCalHist);
339
340 HALDEBUG(ah, HAL_DEBUG_ATTACH, "%s: return\n", __func__);
341
342 return ah;
343bad:
344 if (ahp)
345 ar5416Detach((struct ath_hal *) ahp);
346 if (status)
347 *status = ecode;
348 return AH_NULL;
349}
350
351void
352ar5416Detach(struct ath_hal *ah)
353{
354 HALDEBUG(ah, HAL_DEBUG_ATTACH, "%s:\n", __func__);
355
356 HALASSERT(ah != AH_NULL);
357 HALASSERT(ah->ah_magic == AR5416_MAGIC);
358
359 ar5416AniDetach(ah);
360 ar5212RfDetach(ah);
361 ah->ah_disable(ah);
362 ar5416SetPowerMode(ah, HAL_PM_FULL_SLEEP, AH_TRUE);
363 ath_hal_eepromDetach(ah);
364 ath_hal_free(ah);
365}
366
367/*
368 * Fill all software cached or static hardware state information.
369 * Return failure if capabilities are to come from EEPROM and
370 * cannot be read.
371 */
372HAL_BOOL
373ar5416FillCapabilityInfo(struct ath_hal *ah)
374{
375 struct ath_hal_private *ahpriv = AH_PRIVATE(ah);
376 HAL_CAPABILITIES *pCap = &ahpriv->ah_caps;
377 uint16_t val;
378
379 /* Construct wireless mode from EEPROM */
380 pCap->halWirelessModes = 0;
381 if (ath_hal_eepromGetFlag(ah, AR_EEP_AMODE)) {
382 pCap->halWirelessModes |= HAL_MODE_11A
383 | HAL_MODE_11NA_HT20
384 | HAL_MODE_11NA_HT40PLUS
385 | HAL_MODE_11NA_HT40MINUS
386 ;
387 }
388 if (ath_hal_eepromGetFlag(ah, AR_EEP_GMODE)) {
389 pCap->halWirelessModes |= HAL_MODE_11G
390 | HAL_MODE_11NG_HT20
391 | HAL_MODE_11NG_HT40PLUS
392 | HAL_MODE_11NG_HT40MINUS
393 ;
394 pCap->halWirelessModes |= HAL_MODE_11A
395 | HAL_MODE_11NA_HT20
396 | HAL_MODE_11NA_HT40PLUS
397 | HAL_MODE_11NA_HT40MINUS
398 ;
399 }
400
401 pCap->halLow2GhzChan = 2312;
402 pCap->halHigh2GhzChan = 2732;
403
404 pCap->halLow5GhzChan = 4915;
405 pCap->halHigh5GhzChan = 6100;
406
407 pCap->halCipherCkipSupport = AH_FALSE;
408 pCap->halCipherTkipSupport = AH_TRUE;
409 pCap->halCipherAesCcmSupport = ath_hal_eepromGetFlag(ah, AR_EEP_AES);
410
411 pCap->halMicCkipSupport = AH_FALSE;
412 pCap->halMicTkipSupport = AH_TRUE;
413 pCap->halMicAesCcmSupport = ath_hal_eepromGetFlag(ah, AR_EEP_AES);
414 /*
415 * Starting with Griffin TX+RX mic keys can be combined
416 * in one key cache slot.
417 */
418 pCap->halTkipMicTxRxKeySupport = AH_TRUE;
419 pCap->halChanSpreadSupport = AH_TRUE;
420 pCap->halSleepAfterBeaconBroken = AH_TRUE;
421
422 pCap->halCompressSupport = AH_FALSE;
423 pCap->halBurstSupport = AH_TRUE;
424 pCap->halFastFramesSupport = AH_FALSE; /* XXX? */
425 pCap->halChapTuningSupport = AH_TRUE;
426 pCap->halTurboPrimeSupport = AH_TRUE;
427
428 pCap->halTurboGSupport = pCap->halWirelessModes & HAL_MODE_108G;
429
430 pCap->halPSPollBroken = AH_TRUE; /* XXX fixed in later revs? */
431 pCap->halVEOLSupport = AH_TRUE;
432 pCap->halBssIdMaskSupport = AH_TRUE;
433 pCap->halMcastKeySrchSupport = AH_FALSE;
434 pCap->halTsfAddSupport = AH_TRUE;
435
436 if (ath_hal_eepromGet(ah, AR_EEP_MAXQCU, &val) == HAL_OK)
437 pCap->halTotalQueues = val;
438 else
439 pCap->halTotalQueues = HAL_NUM_TX_QUEUES;
440
441 if (ath_hal_eepromGet(ah, AR_EEP_KCENTRIES, &val) == HAL_OK)
442 pCap->halKeyCacheSize = val;
443 else
444 pCap->halKeyCacheSize = AR5416_KEYTABLE_SIZE;
445
446 /* XXX not needed */
447 pCap->halChanHalfRate = AH_FALSE; /* XXX ? */
448 pCap->halChanQuarterRate = AH_FALSE; /* XXX ? */
449
450 pCap->halTstampPrecision = 32;
451 pCap->halHwPhyCounterSupport = AH_TRUE;
452
453 pCap->halFastCCSupport = AH_TRUE;
454 pCap->halNumGpioPins = 6;
455 pCap->halWowSupport = AH_FALSE;
456 pCap->halWowMatchPatternExact = AH_FALSE;
457 pCap->halBtCoexSupport = AH_FALSE; /* XXX need support */
458 pCap->halAutoSleepSupport = AH_FALSE;
459#if 0 /* XXX not yet */
460 pCap->halNumAntCfg2GHz = ar5416GetNumAntConfig(ahp, HAL_FREQ_BAND_2GHZ);
461 pCap->halNumAntCfg5GHz = ar5416GetNumAntConfig(ahp, HAL_FREQ_BAND_5GHZ);
462#endif
463 pCap->halHTSupport = AH_TRUE;
464 pCap->halTxChainMask = ath_hal_eepromGet(ah, AR_EEP_TXMASK, AH_NULL);
465 /* XXX CB71 uses GPIO 0 to indicate 3 rx chains */
466 pCap->halRxChainMask = ath_hal_eepromGet(ah, AR_EEP_RXMASK, AH_NULL);
467 pCap->halRtsAggrLimit = 8*1024; /* Owl 2.0 limit */
468 pCap->halMbssidAggrSupport = AH_TRUE;
469 pCap->halForcePpmSupport = AH_TRUE;
470 pCap->halEnhancedPmSupport = AH_TRUE;
471
472 if (ath_hal_eepromGetFlag(ah, AR_EEP_RFKILL) &&
473 ath_hal_eepromGet(ah, AR_EEP_RFSILENT, &ahpriv->ah_rfsilent) == HAL_OK) {
474 /* NB: enabled by default */
475 ahpriv->ah_rfkillEnabled = AH_TRUE;
476 pCap->halRfSilentSupport = AH_TRUE;
477 }
478
479 ahpriv->ah_rxornIsFatal = AH_FALSE;
480
481 return AH_TRUE;
482}
483#endif /* AH_SUPPORT_AR5416 */