1572ff6f6SMatthew Dillon /*
2572ff6f6SMatthew Dillon  * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
3572ff6f6SMatthew Dillon  * Copyright (c) 2002-2008 Atheros Communications, Inc.
4572ff6f6SMatthew Dillon  *
5572ff6f6SMatthew Dillon  * Permission to use, copy, modify, and/or distribute this software for any
6572ff6f6SMatthew Dillon  * purpose with or without fee is hereby granted, provided that the above
7572ff6f6SMatthew Dillon  * copyright notice and this permission notice appear in all copies.
8572ff6f6SMatthew Dillon  *
9572ff6f6SMatthew Dillon  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10572ff6f6SMatthew Dillon  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11572ff6f6SMatthew Dillon  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12572ff6f6SMatthew Dillon  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13572ff6f6SMatthew Dillon  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14572ff6f6SMatthew Dillon  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15572ff6f6SMatthew Dillon  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16572ff6f6SMatthew Dillon  *
17572ff6f6SMatthew Dillon  * $FreeBSD$
18572ff6f6SMatthew Dillon  */
19572ff6f6SMatthew Dillon #include "opt_ah.h"
20572ff6f6SMatthew Dillon 
21572ff6f6SMatthew Dillon #include "ah.h"
22572ff6f6SMatthew Dillon #include "ah_internal.h"
23572ff6f6SMatthew Dillon #include "ah_devid.h"
24572ff6f6SMatthew Dillon 
25572ff6f6SMatthew Dillon #include "ah_eeprom_v14.h"
26572ff6f6SMatthew Dillon 
27572ff6f6SMatthew Dillon #include "ar5416/ar5416.h"
28572ff6f6SMatthew Dillon #include "ar5416/ar5416reg.h"
29572ff6f6SMatthew Dillon #include "ar5416/ar5416phy.h"
30572ff6f6SMatthew Dillon 
31572ff6f6SMatthew Dillon #include "ar5416/ar5416.ini"
32572ff6f6SMatthew Dillon 
33572ff6f6SMatthew Dillon static void ar5416ConfigPCIE(struct ath_hal *ah, HAL_BOOL restore,
34572ff6f6SMatthew Dillon 		HAL_BOOL power_off);
35572ff6f6SMatthew Dillon static void ar5416DisablePCIE(struct ath_hal *ah);
36572ff6f6SMatthew Dillon static void ar5416WriteIni(struct ath_hal *ah,
37572ff6f6SMatthew Dillon 	    const struct ieee80211_channel *chan);
38572ff6f6SMatthew Dillon static void ar5416SpurMitigate(struct ath_hal *ah,
39572ff6f6SMatthew Dillon 	    const struct ieee80211_channel *chan);
40572ff6f6SMatthew Dillon 
41572ff6f6SMatthew Dillon static void
ar5416AniSetup(struct ath_hal * ah)42572ff6f6SMatthew Dillon ar5416AniSetup(struct ath_hal *ah)
43572ff6f6SMatthew Dillon {
44572ff6f6SMatthew Dillon 	static const struct ar5212AniParams aniparams = {
45572ff6f6SMatthew Dillon 		.maxNoiseImmunityLevel	= 4,	/* levels 0..4 */
46572ff6f6SMatthew Dillon 		.totalSizeDesired	= { -55, -55, -55, -55, -62 },
47572ff6f6SMatthew Dillon 		.coarseHigh		= { -14, -14, -14, -14, -12 },
48572ff6f6SMatthew Dillon 		.coarseLow		= { -64, -64, -64, -64, -70 },
49572ff6f6SMatthew Dillon 		.firpwr			= { -78, -78, -78, -78, -80 },
50572ff6f6SMatthew Dillon 		.maxSpurImmunityLevel	= 7,
51572ff6f6SMatthew Dillon 		.cycPwrThr1		= { 2, 4, 6, 8, 10, 12, 14, 16 },
52572ff6f6SMatthew Dillon 		.maxFirstepLevel	= 2,	/* levels 0..2 */
53572ff6f6SMatthew Dillon 		.firstep		= { 0, 4, 8 },
54572ff6f6SMatthew Dillon 		.ofdmTrigHigh		= 500,
55572ff6f6SMatthew Dillon 		.ofdmTrigLow		= 200,
56572ff6f6SMatthew Dillon 		.cckTrigHigh		= 200,
57572ff6f6SMatthew Dillon 		.cckTrigLow		= 100,
58572ff6f6SMatthew Dillon 		.rssiThrHigh		= 40,
59572ff6f6SMatthew Dillon 		.rssiThrLow		= 7,
60572ff6f6SMatthew Dillon 		.period			= 100,
61572ff6f6SMatthew Dillon 	};
62572ff6f6SMatthew Dillon 	/* NB: disable ANI noise immmunity for reliable RIFS rx */
63572ff6f6SMatthew Dillon 	AH5416(ah)->ah_ani_function &= ~(1 << HAL_ANI_NOISE_IMMUNITY_LEVEL);
64572ff6f6SMatthew Dillon 	ar5416AniAttach(ah, &aniparams, &aniparams, AH_TRUE);
65572ff6f6SMatthew Dillon }
66572ff6f6SMatthew Dillon 
67572ff6f6SMatthew Dillon /*
68572ff6f6SMatthew Dillon  * AR5416 doesn't do OLC or temperature compensation.
69572ff6f6SMatthew Dillon  */
70572ff6f6SMatthew Dillon static void
ar5416olcInit(struct ath_hal * ah)71572ff6f6SMatthew Dillon ar5416olcInit(struct ath_hal *ah)
72572ff6f6SMatthew Dillon {
73572ff6f6SMatthew Dillon }
74572ff6f6SMatthew Dillon 
75572ff6f6SMatthew Dillon static void
ar5416olcTempCompensation(struct ath_hal * ah)76572ff6f6SMatthew Dillon ar5416olcTempCompensation(struct ath_hal *ah)
77572ff6f6SMatthew Dillon {
78572ff6f6SMatthew Dillon }
79572ff6f6SMatthew Dillon 
80572ff6f6SMatthew Dillon /*
81572ff6f6SMatthew Dillon  * Attach for an AR5416 part.
82572ff6f6SMatthew Dillon  */
83572ff6f6SMatthew Dillon void
ar5416InitState(struct ath_hal_5416 * ahp5416,uint16_t devid,HAL_SOFTC sc,HAL_BUS_TAG st,HAL_BUS_HANDLE sh,HAL_STATUS * status)84572ff6f6SMatthew Dillon ar5416InitState(struct ath_hal_5416 *ahp5416, uint16_t devid, HAL_SOFTC sc,
85572ff6f6SMatthew Dillon 	HAL_BUS_TAG st, HAL_BUS_HANDLE sh, HAL_STATUS *status)
86572ff6f6SMatthew Dillon {
87572ff6f6SMatthew Dillon 	struct ath_hal_5212 *ahp;
88572ff6f6SMatthew Dillon 	struct ath_hal *ah;
89572ff6f6SMatthew Dillon 
90572ff6f6SMatthew Dillon 	ahp = &ahp5416->ah_5212;
91572ff6f6SMatthew Dillon 	ar5212InitState(ahp, devid, sc, st, sh, status);
92572ff6f6SMatthew Dillon 	ah = &ahp->ah_priv.h;
93572ff6f6SMatthew Dillon 
94572ff6f6SMatthew Dillon 	/* override 5212 methods for our needs */
95572ff6f6SMatthew Dillon 	ah->ah_magic			= AR5416_MAGIC;
96572ff6f6SMatthew Dillon 	ah->ah_getRateTable		= ar5416GetRateTable;
97572ff6f6SMatthew Dillon 	ah->ah_detach			= ar5416Detach;
98572ff6f6SMatthew Dillon 
99572ff6f6SMatthew Dillon 	/* Reset functions */
100572ff6f6SMatthew Dillon 	ah->ah_reset			= ar5416Reset;
101572ff6f6SMatthew Dillon 	ah->ah_phyDisable		= ar5416PhyDisable;
102572ff6f6SMatthew Dillon 	ah->ah_disable			= ar5416Disable;
103572ff6f6SMatthew Dillon 	ah->ah_configPCIE		= ar5416ConfigPCIE;
104572ff6f6SMatthew Dillon 	ah->ah_disablePCIE		= ar5416DisablePCIE;
105572ff6f6SMatthew Dillon 	ah->ah_perCalibration		= ar5416PerCalibration;
106*3a05fd2aSSascha Wildner 	ah->ah_perCalibrationN		= ar5416PerCalibrationN;
107*3a05fd2aSSascha Wildner 	ah->ah_resetCalValid		= ar5416ResetCalValid;
108572ff6f6SMatthew Dillon 	ah->ah_setTxPowerLimit		= ar5416SetTxPowerLimit;
109572ff6f6SMatthew Dillon 	ah->ah_setTxPower		= ar5416SetTransmitPower;
110572ff6f6SMatthew Dillon 	ah->ah_setBoardValues		= ar5416SetBoardValues;
111572ff6f6SMatthew Dillon 
112572ff6f6SMatthew Dillon 	/* Transmit functions */
113572ff6f6SMatthew Dillon 	ah->ah_stopTxDma		= ar5416StopTxDma;
114572ff6f6SMatthew Dillon 	ah->ah_setupTxDesc		= ar5416SetupTxDesc;
115572ff6f6SMatthew Dillon 	ah->ah_setupXTxDesc		= ar5416SetupXTxDesc;
116572ff6f6SMatthew Dillon 	ah->ah_fillTxDesc		= ar5416FillTxDesc;
117572ff6f6SMatthew Dillon 	ah->ah_procTxDesc		= ar5416ProcTxDesc;
118572ff6f6SMatthew Dillon 	ah->ah_getTxCompletionRates	= ar5416GetTxCompletionRates;
119572ff6f6SMatthew Dillon 	ah->ah_setupTxQueue		= ar5416SetupTxQueue;
120572ff6f6SMatthew Dillon 	ah->ah_resetTxQueue		= ar5416ResetTxQueue;
121572ff6f6SMatthew Dillon 
122572ff6f6SMatthew Dillon 	/* Receive Functions */
123572ff6f6SMatthew Dillon 	ah->ah_getRxFilter		= ar5416GetRxFilter;
124572ff6f6SMatthew Dillon 	ah->ah_setRxFilter		= ar5416SetRxFilter;
125572ff6f6SMatthew Dillon 	ah->ah_stopDmaReceive		= ar5416StopDmaReceive;
126572ff6f6SMatthew Dillon 	ah->ah_startPcuReceive		= ar5416StartPcuReceive;
127572ff6f6SMatthew Dillon 	ah->ah_stopPcuReceive		= ar5416StopPcuReceive;
128572ff6f6SMatthew Dillon 	ah->ah_setupRxDesc		= ar5416SetupRxDesc;
129572ff6f6SMatthew Dillon 	ah->ah_procRxDesc		= ar5416ProcRxDesc;
130572ff6f6SMatthew Dillon 	ah->ah_rxMonitor		= ar5416RxMonitor;
131572ff6f6SMatthew Dillon 	ah->ah_aniPoll			= ar5416AniPoll;
132572ff6f6SMatthew Dillon 	ah->ah_procMibEvent		= ar5416ProcessMibIntr;
133572ff6f6SMatthew Dillon 
134572ff6f6SMatthew Dillon 	/* Misc Functions */
135572ff6f6SMatthew Dillon 	ah->ah_getCapability		= ar5416GetCapability;
136572ff6f6SMatthew Dillon 	ah->ah_setCapability		= ar5416SetCapability;
137572ff6f6SMatthew Dillon 	ah->ah_getDiagState		= ar5416GetDiagState;
138572ff6f6SMatthew Dillon 	ah->ah_setLedState		= ar5416SetLedState;
139572ff6f6SMatthew Dillon 	ah->ah_gpioCfgOutput		= ar5416GpioCfgOutput;
140572ff6f6SMatthew Dillon 	ah->ah_gpioCfgInput		= ar5416GpioCfgInput;
141572ff6f6SMatthew Dillon 	ah->ah_gpioGet			= ar5416GpioGet;
142572ff6f6SMatthew Dillon 	ah->ah_gpioSet			= ar5416GpioSet;
143572ff6f6SMatthew Dillon 	ah->ah_gpioSetIntr		= ar5416GpioSetIntr;
144572ff6f6SMatthew Dillon 	ah->ah_getTsf64			= ar5416GetTsf64;
145572ff6f6SMatthew Dillon 	ah->ah_setTsf64			= ar5416SetTsf64;
146572ff6f6SMatthew Dillon 	ah->ah_resetTsf			= ar5416ResetTsf;
147572ff6f6SMatthew Dillon 	ah->ah_getRfGain		= ar5416GetRfgain;
148572ff6f6SMatthew Dillon 	ah->ah_setAntennaSwitch		= ar5416SetAntennaSwitch;
149572ff6f6SMatthew Dillon 	ah->ah_setDecompMask		= ar5416SetDecompMask;
150572ff6f6SMatthew Dillon 	ah->ah_setCoverageClass		= ar5416SetCoverageClass;
151572ff6f6SMatthew Dillon 	ah->ah_setQuiet			= ar5416SetQuiet;
152572ff6f6SMatthew Dillon 	ah->ah_getMibCycleCounts	= ar5416GetMibCycleCounts;
153572ff6f6SMatthew Dillon 	ah->ah_setChainMasks		= ar5416SetChainMasks;
154572ff6f6SMatthew Dillon 
155572ff6f6SMatthew Dillon 	ah->ah_resetKeyCacheEntry	= ar5416ResetKeyCacheEntry;
156572ff6f6SMatthew Dillon 	ah->ah_setKeyCacheEntry		= ar5416SetKeyCacheEntry;
157572ff6f6SMatthew Dillon 
158572ff6f6SMatthew Dillon 	/* DFS Functions */
159572ff6f6SMatthew Dillon 	ah->ah_enableDfs		= ar5416EnableDfs;
160572ff6f6SMatthew Dillon 	ah->ah_getDfsThresh		= ar5416GetDfsThresh;
161572ff6f6SMatthew Dillon 	ah->ah_getDfsDefaultThresh	= ar5416GetDfsDefaultThresh;
162572ff6f6SMatthew Dillon 	ah->ah_procRadarEvent		= ar5416ProcessRadarEvent;
163572ff6f6SMatthew Dillon 	ah->ah_isFastClockEnabled	= ar5416IsFastClockEnabled;
164572ff6f6SMatthew Dillon 
165572ff6f6SMatthew Dillon 	/* Spectral Scan Functions */
166572ff6f6SMatthew Dillon 	ah->ah_spectralConfigure	= ar5416ConfigureSpectralScan;
167572ff6f6SMatthew Dillon 	ah->ah_spectralGetConfig	= ar5416GetSpectralParams;
168572ff6f6SMatthew Dillon 	ah->ah_spectralStart		= ar5416StartSpectralScan;
169572ff6f6SMatthew Dillon 	ah->ah_spectralStop		= ar5416StopSpectralScan;
170572ff6f6SMatthew Dillon 	ah->ah_spectralIsEnabled	= ar5416IsSpectralEnabled;
171572ff6f6SMatthew Dillon 	ah->ah_spectralIsActive		= ar5416IsSpectralActive;
172572ff6f6SMatthew Dillon 
173572ff6f6SMatthew Dillon 	/* Power Management Functions */
174572ff6f6SMatthew Dillon 	ah->ah_setPowerMode		= ar5416SetPowerMode;
175572ff6f6SMatthew Dillon 
176572ff6f6SMatthew Dillon 	/* Beacon Management Functions */
177572ff6f6SMatthew Dillon 	ah->ah_setBeaconTimers		= ar5416SetBeaconTimers;
178572ff6f6SMatthew Dillon 	ah->ah_beaconInit		= ar5416BeaconInit;
179572ff6f6SMatthew Dillon 	ah->ah_setStationBeaconTimers	= ar5416SetStaBeaconTimers;
180572ff6f6SMatthew Dillon 	ah->ah_resetStationBeaconTimers	= ar5416ResetStaBeaconTimers;
181572ff6f6SMatthew Dillon 	ah->ah_getNextTBTT		= ar5416GetNextTBTT;
182572ff6f6SMatthew Dillon 
183572ff6f6SMatthew Dillon 	/* 802.11n Functions */
184572ff6f6SMatthew Dillon 	ah->ah_chainTxDesc		= ar5416ChainTxDesc;
185572ff6f6SMatthew Dillon 	ah->ah_setupFirstTxDesc		= ar5416SetupFirstTxDesc;
186572ff6f6SMatthew Dillon 	ah->ah_setupLastTxDesc		= ar5416SetupLastTxDesc;
187572ff6f6SMatthew Dillon 	ah->ah_set11nRateScenario	= ar5416Set11nRateScenario;
188572ff6f6SMatthew Dillon 	ah->ah_set11nAggrFirst		= ar5416Set11nAggrFirst;
189572ff6f6SMatthew Dillon 	ah->ah_set11nAggrMiddle		= ar5416Set11nAggrMiddle;
190572ff6f6SMatthew Dillon 	ah->ah_set11nAggrLast		= ar5416Set11nAggrLast;
191572ff6f6SMatthew Dillon 	ah->ah_clr11nAggr		= ar5416Clr11nAggr;
192572ff6f6SMatthew Dillon 	ah->ah_set11nBurstDuration	= ar5416Set11nBurstDuration;
193572ff6f6SMatthew Dillon 	ah->ah_get11nExtBusy		= ar5416Get11nExtBusy;
194572ff6f6SMatthew Dillon 	ah->ah_set11nMac2040		= ar5416Set11nMac2040;
195572ff6f6SMatthew Dillon 	ah->ah_get11nRxClear		= ar5416Get11nRxClear;
196572ff6f6SMatthew Dillon 	ah->ah_set11nRxClear		= ar5416Set11nRxClear;
197572ff6f6SMatthew Dillon 	ah->ah_set11nVirtMoreFrag	= ar5416Set11nVirtualMoreFrag;
198572ff6f6SMatthew Dillon 
199572ff6f6SMatthew Dillon 	/* Interrupt functions */
200572ff6f6SMatthew Dillon 	ah->ah_isInterruptPending	= ar5416IsInterruptPending;
201572ff6f6SMatthew Dillon 	ah->ah_getPendingInterrupts	= ar5416GetPendingInterrupts;
202572ff6f6SMatthew Dillon 	ah->ah_setInterrupts		= ar5416SetInterrupts;
203572ff6f6SMatthew Dillon 
204572ff6f6SMatthew Dillon 	/* Bluetooth Coexistence functions */
205572ff6f6SMatthew Dillon 	ah->ah_btCoexSetInfo		= ar5416SetBTCoexInfo;
206572ff6f6SMatthew Dillon 	ah->ah_btCoexSetConfig		= ar5416BTCoexConfig;
207572ff6f6SMatthew Dillon 	ah->ah_btCoexSetQcuThresh	= ar5416BTCoexSetQcuThresh;
208572ff6f6SMatthew Dillon 	ah->ah_btCoexSetWeights		= ar5416BTCoexSetWeights;
209572ff6f6SMatthew Dillon 	ah->ah_btCoexSetBmissThresh	= ar5416BTCoexSetupBmissThresh;
210572ff6f6SMatthew Dillon 	ah->ah_btCoexSetParameter	= ar5416BTCoexSetParameter;
211572ff6f6SMatthew Dillon 	ah->ah_btCoexDisable		= ar5416BTCoexDisable;
212572ff6f6SMatthew Dillon 	ah->ah_btCoexEnable		= ar5416BTCoexEnable;
213572ff6f6SMatthew Dillon 	AH5416(ah)->ah_btCoexSetDiversity = ar5416BTCoexAntennaDiversity;
214572ff6f6SMatthew Dillon 
215572ff6f6SMatthew Dillon 	ahp->ah_priv.ah_getWirelessModes= ar5416GetWirelessModes;
216572ff6f6SMatthew Dillon 	ahp->ah_priv.ah_eepromRead	= ar5416EepromRead;
217572ff6f6SMatthew Dillon #ifdef AH_SUPPORT_WRITE_EEPROM
218572ff6f6SMatthew Dillon 	ahp->ah_priv.ah_eepromWrite	= ar5416EepromWrite;
219572ff6f6SMatthew Dillon #endif
220572ff6f6SMatthew Dillon 	ahp->ah_priv.ah_getChipPowerLimits = ar5416GetChipPowerLimits;
221572ff6f6SMatthew Dillon 
222572ff6f6SMatthew Dillon 	/* Internal ops */
223572ff6f6SMatthew Dillon 	AH5416(ah)->ah_writeIni		= ar5416WriteIni;
224572ff6f6SMatthew Dillon 	AH5416(ah)->ah_spurMitigate	= ar5416SpurMitigate;
225572ff6f6SMatthew Dillon 
226572ff6f6SMatthew Dillon 	/* Internal baseband ops */
227572ff6f6SMatthew Dillon 	AH5416(ah)->ah_initPLL		= ar5416InitPLL;
228572ff6f6SMatthew Dillon 
229572ff6f6SMatthew Dillon 	/* Internal calibration ops */
230572ff6f6SMatthew Dillon 	AH5416(ah)->ah_cal_initcal	= ar5416InitCalHardware;
231572ff6f6SMatthew Dillon 
232572ff6f6SMatthew Dillon 	/* Internal TX power control related operations */
233572ff6f6SMatthew Dillon 	AH5416(ah)->ah_olcInit = ar5416olcInit;
234572ff6f6SMatthew Dillon 	AH5416(ah)->ah_olcTempCompensation	= ar5416olcTempCompensation;
235572ff6f6SMatthew Dillon 	AH5416(ah)->ah_setPowerCalTable	= ar5416SetPowerCalTable;
236572ff6f6SMatthew Dillon 
237572ff6f6SMatthew Dillon 	/*
238572ff6f6SMatthew Dillon 	 * Start by setting all Owl devices to 2x2
239572ff6f6SMatthew Dillon 	 */
240572ff6f6SMatthew Dillon 	AH5416(ah)->ah_rx_chainmask = AR5416_DEFAULT_RXCHAINMASK;
241572ff6f6SMatthew Dillon 	AH5416(ah)->ah_tx_chainmask = AR5416_DEFAULT_TXCHAINMASK;
242572ff6f6SMatthew Dillon 
243572ff6f6SMatthew Dillon 	/* Enable all ANI functions to begin with */
244572ff6f6SMatthew Dillon 	AH5416(ah)->ah_ani_function = 0xffffffff;
245572ff6f6SMatthew Dillon 
246572ff6f6SMatthew Dillon 	/* Set overridable ANI methods */
247572ff6f6SMatthew Dillon 	AH5212(ah)->ah_aniControl = ar5416AniControl;
248572ff6f6SMatthew Dillon 
249572ff6f6SMatthew Dillon 	/*
250572ff6f6SMatthew Dillon 	 * Default FIFO Trigger levels
251572ff6f6SMatthew Dillon 	 *
252572ff6f6SMatthew Dillon 	 * These define how filled the TX FIFO needs to be before
253572ff6f6SMatthew Dillon 	 * the baseband begins to be given some data.
254572ff6f6SMatthew Dillon 	 *
255572ff6f6SMatthew Dillon 	 * To be paranoid, we ensure that the TX trigger level always
256572ff6f6SMatthew Dillon 	 * has at least enough space for two TX DMA to occur.
257572ff6f6SMatthew Dillon 	 * The TX DMA size is currently hard-coded to AR_TXCFG_DMASZ_128B.
258572ff6f6SMatthew Dillon 	 * That means we need to leave at least 256 bytes available in
259572ff6f6SMatthew Dillon 	 * the TX DMA FIFO.
260572ff6f6SMatthew Dillon 	 */
261572ff6f6SMatthew Dillon #define	AR_FTRIG_512B	0x00000080 // 5 bits total
262572ff6f6SMatthew Dillon 	/*
263572ff6f6SMatthew Dillon 	 * AR9285/AR9271 have half the size TX FIFO compared to
264572ff6f6SMatthew Dillon 	 * other devices
265572ff6f6SMatthew Dillon 	 */
266572ff6f6SMatthew Dillon 	if (AR_SREV_KITE(ah) || AR_SREV_9271(ah)) {
267572ff6f6SMatthew Dillon 		AH5212(ah)->ah_txTrigLev = (AR_FTRIG_256B >> AR_FTRIG_S);
268572ff6f6SMatthew Dillon 		AH5212(ah)->ah_maxTxTrigLev = ((2048 / 64) - 1);
269572ff6f6SMatthew Dillon 	} else {
270572ff6f6SMatthew Dillon 		AH5212(ah)->ah_txTrigLev = (AR_FTRIG_512B >> AR_FTRIG_S);
271572ff6f6SMatthew Dillon 		AH5212(ah)->ah_maxTxTrigLev = ((4096 / 64) - 1);
272572ff6f6SMatthew Dillon 	}
273572ff6f6SMatthew Dillon #undef	AR_FTRIG_512B
274572ff6f6SMatthew Dillon 
275572ff6f6SMatthew Dillon 	/* And now leave some headspace - 256 bytes */
276572ff6f6SMatthew Dillon 	AH5212(ah)->ah_maxTxTrigLev -= 4;
277572ff6f6SMatthew Dillon }
278572ff6f6SMatthew Dillon 
279572ff6f6SMatthew Dillon uint32_t
ar5416GetRadioRev(struct ath_hal * ah)280572ff6f6SMatthew Dillon ar5416GetRadioRev(struct ath_hal *ah)
281572ff6f6SMatthew Dillon {
282572ff6f6SMatthew Dillon 	uint32_t val;
283572ff6f6SMatthew Dillon 	int i;
284572ff6f6SMatthew Dillon 
285572ff6f6SMatthew Dillon 	/* Read Radio Chip Rev Extract */
286572ff6f6SMatthew Dillon 	OS_REG_WRITE(ah, AR_PHY(0x36), 0x00007058);
287572ff6f6SMatthew Dillon 	for (i = 0; i < 8; i++)
288572ff6f6SMatthew Dillon 		OS_REG_WRITE(ah, AR_PHY(0x20), 0x00010000);
289572ff6f6SMatthew Dillon 	val = (OS_REG_READ(ah, AR_PHY(256)) >> 24) & 0xff;
290572ff6f6SMatthew Dillon 	val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4);
291572ff6f6SMatthew Dillon 	return ath_hal_reverseBits(val, 8);
292572ff6f6SMatthew Dillon }
293572ff6f6SMatthew Dillon 
294572ff6f6SMatthew Dillon /*
295572ff6f6SMatthew Dillon  * Attach for an AR5416 part.
296572ff6f6SMatthew Dillon  */
297572ff6f6SMatthew Dillon static struct ath_hal *
ar5416Attach(uint16_t devid,HAL_SOFTC sc,HAL_BUS_TAG st,HAL_BUS_HANDLE sh,uint16_t * eepromdata,HAL_OPS_CONFIG * ah_config,HAL_STATUS * status)298572ff6f6SMatthew Dillon ar5416Attach(uint16_t devid, HAL_SOFTC sc,
299572ff6f6SMatthew Dillon 	HAL_BUS_TAG st, HAL_BUS_HANDLE sh, uint16_t *eepromdata,
300848b370cSMatthew Dillon 	HAL_OPS_CONFIG *ah_config, HAL_STATUS *status)
301572ff6f6SMatthew Dillon {
302572ff6f6SMatthew Dillon 	struct ath_hal_5416 *ahp5416;
303572ff6f6SMatthew Dillon 	struct ath_hal_5212 *ahp;
304572ff6f6SMatthew Dillon 	struct ath_hal *ah;
305572ff6f6SMatthew Dillon 	uint32_t val;
306572ff6f6SMatthew Dillon 	HAL_STATUS ecode;
307572ff6f6SMatthew Dillon 	HAL_BOOL rfStatus;
308572ff6f6SMatthew Dillon 
309572ff6f6SMatthew Dillon 	HALDEBUG(AH_NULL, HAL_DEBUG_ATTACH, "%s: sc %p st %p sh %p\n",
310572ff6f6SMatthew Dillon 	    __func__, sc, (void*) st, (void*) sh);
311572ff6f6SMatthew Dillon 
312572ff6f6SMatthew Dillon 	/* NB: memory is returned zero'd */
313572ff6f6SMatthew Dillon 	ahp5416 = ath_hal_malloc(sizeof (struct ath_hal_5416) +
314572ff6f6SMatthew Dillon 		/* extra space for Owl 2.1/2.2 WAR */
315572ff6f6SMatthew Dillon 		sizeof(ar5416Addac)
316572ff6f6SMatthew Dillon 	);
317572ff6f6SMatthew Dillon 	if (ahp5416 == AH_NULL) {
318572ff6f6SMatthew Dillon 		HALDEBUG(AH_NULL, HAL_DEBUG_ANY,
319572ff6f6SMatthew Dillon 		    "%s: cannot allocate memory for state block\n", __func__);
320572ff6f6SMatthew Dillon 		*status = HAL_ENOMEM;
321572ff6f6SMatthew Dillon 		return AH_NULL;
322572ff6f6SMatthew Dillon 	}
323572ff6f6SMatthew Dillon 	ar5416InitState(ahp5416, devid, sc, st, sh, status);
324572ff6f6SMatthew Dillon 	ahp = &ahp5416->ah_5212;
325572ff6f6SMatthew Dillon 	ah = &ahp->ah_priv.h;
326572ff6f6SMatthew Dillon 
327572ff6f6SMatthew Dillon 	if (!ar5416SetResetReg(ah, HAL_RESET_POWER_ON)) {
328572ff6f6SMatthew Dillon 		/* reset chip */
329572ff6f6SMatthew Dillon 		HALDEBUG(ah, HAL_DEBUG_ANY, "%s: couldn't reset chip\n", __func__);
330572ff6f6SMatthew Dillon 		ecode = HAL_EIO;
331572ff6f6SMatthew Dillon 		goto bad;
332572ff6f6SMatthew Dillon 	}
333572ff6f6SMatthew Dillon 
334572ff6f6SMatthew Dillon 	if (!ar5416SetPowerMode(ah, HAL_PM_AWAKE, AH_TRUE)) {
335572ff6f6SMatthew Dillon 		HALDEBUG(ah, HAL_DEBUG_ANY, "%s: couldn't wakeup chip\n", __func__);
336572ff6f6SMatthew Dillon 		ecode = HAL_EIO;
337572ff6f6SMatthew Dillon 		goto bad;
338572ff6f6SMatthew Dillon 	}
339572ff6f6SMatthew Dillon 	/* Read Revisions from Chips before taking out of reset */
340572ff6f6SMatthew Dillon 	val = OS_REG_READ(ah, AR_SREV) & AR_SREV_ID;
341572ff6f6SMatthew Dillon 	AH_PRIVATE(ah)->ah_macVersion = val >> AR_SREV_ID_S;
342572ff6f6SMatthew Dillon 	AH_PRIVATE(ah)->ah_macRev = val & AR_SREV_REVISION;
343572ff6f6SMatthew Dillon 	AH_PRIVATE(ah)->ah_ispcie = (devid == AR5416_DEVID_PCIE);
344572ff6f6SMatthew Dillon 
345572ff6f6SMatthew Dillon 	/* setup common ini data; rf backends handle remainder */
346572ff6f6SMatthew Dillon 	HAL_INI_INIT(&ahp->ah_ini_modes, ar5416Modes, 6);
347572ff6f6SMatthew Dillon 	HAL_INI_INIT(&ahp->ah_ini_common, ar5416Common, 2);
348572ff6f6SMatthew Dillon 
349572ff6f6SMatthew Dillon 	HAL_INI_INIT(&AH5416(ah)->ah_ini_bb_rfgain, ar5416BB_RfGain, 3);
350572ff6f6SMatthew Dillon 	HAL_INI_INIT(&AH5416(ah)->ah_ini_bank0, ar5416Bank0, 2);
351572ff6f6SMatthew Dillon 	HAL_INI_INIT(&AH5416(ah)->ah_ini_bank1, ar5416Bank1, 2);
352572ff6f6SMatthew Dillon 	HAL_INI_INIT(&AH5416(ah)->ah_ini_bank2, ar5416Bank2, 2);
353572ff6f6SMatthew Dillon 	HAL_INI_INIT(&AH5416(ah)->ah_ini_bank3, ar5416Bank3, 3);
354572ff6f6SMatthew Dillon 	HAL_INI_INIT(&AH5416(ah)->ah_ini_bank6, ar5416Bank6, 3);
355572ff6f6SMatthew Dillon 	HAL_INI_INIT(&AH5416(ah)->ah_ini_bank7, ar5416Bank7, 2);
356572ff6f6SMatthew Dillon 	HAL_INI_INIT(&AH5416(ah)->ah_ini_addac, ar5416Addac, 2);
357572ff6f6SMatthew Dillon 
358572ff6f6SMatthew Dillon 	if (! IS_5416V2_2(ah)) {		/* Owl 2.1/2.0 */
359572ff6f6SMatthew Dillon 		ath_hal_printf(ah, "[ath] Enabling CLKDRV workaround for AR5416 < v2.2\n");
360572ff6f6SMatthew Dillon 		struct ini {
361572ff6f6SMatthew Dillon 			uint32_t	*data;		/* NB: !const */
362572ff6f6SMatthew Dillon 			int		rows, cols;
363572ff6f6SMatthew Dillon 		};
364572ff6f6SMatthew Dillon 		/* override CLKDRV value */
365572ff6f6SMatthew Dillon 		OS_MEMCPY(&AH5416(ah)[1], ar5416Addac, sizeof(ar5416Addac));
366572ff6f6SMatthew Dillon 		AH5416(ah)->ah_ini_addac.data = (uint32_t *) &AH5416(ah)[1];
367572ff6f6SMatthew Dillon 		HAL_INI_VAL((struct ini *)&AH5416(ah)->ah_ini_addac, 31, 1) = 0;
368572ff6f6SMatthew Dillon 	}
369572ff6f6SMatthew Dillon 
370572ff6f6SMatthew Dillon 	HAL_INI_INIT(&AH5416(ah)->ah_ini_pcieserdes, ar5416PciePhy, 2);
371572ff6f6SMatthew Dillon 	ar5416AttachPCIE(ah);
372572ff6f6SMatthew Dillon 
373572ff6f6SMatthew Dillon 	ecode = ath_hal_v14EepromAttach(ah);
374572ff6f6SMatthew Dillon 	if (ecode != HAL_OK)
375572ff6f6SMatthew Dillon 		goto bad;
376572ff6f6SMatthew Dillon 
377572ff6f6SMatthew Dillon 	if (!ar5416ChipReset(ah, AH_NULL)) {	/* reset chip */
378572ff6f6SMatthew Dillon 		HALDEBUG(ah, HAL_DEBUG_ANY, "%s: chip reset failed\n",
379572ff6f6SMatthew Dillon 		    __func__);
380572ff6f6SMatthew Dillon 		ecode = HAL_EIO;
381572ff6f6SMatthew Dillon 		goto bad;
382572ff6f6SMatthew Dillon 	}
383572ff6f6SMatthew Dillon 
384572ff6f6SMatthew Dillon 	AH_PRIVATE(ah)->ah_phyRev = OS_REG_READ(ah, AR_PHY_CHIP_ID);
385572ff6f6SMatthew Dillon 
386572ff6f6SMatthew Dillon 	if (!ar5212ChipTest(ah)) {
387572ff6f6SMatthew Dillon 		HALDEBUG(ah, HAL_DEBUG_ANY, "%s: hardware self-test failed\n",
388572ff6f6SMatthew Dillon 		    __func__);
389572ff6f6SMatthew Dillon 		ecode = HAL_ESELFTEST;
390572ff6f6SMatthew Dillon 		goto bad;
391572ff6f6SMatthew Dillon 	}
392572ff6f6SMatthew Dillon 
393572ff6f6SMatthew Dillon 	/*
394572ff6f6SMatthew Dillon 	 * Set correct Baseband to analog shift
395572ff6f6SMatthew Dillon 	 * setting to access analog chips.
396572ff6f6SMatthew Dillon 	 */
397572ff6f6SMatthew Dillon 	OS_REG_WRITE(ah, AR_PHY(0), 0x00000007);
398572ff6f6SMatthew Dillon 
399572ff6f6SMatthew Dillon 	/* Read Radio Chip Rev Extract */
400572ff6f6SMatthew Dillon 	AH_PRIVATE(ah)->ah_analog5GhzRev = ar5416GetRadioRev(ah);
401572ff6f6SMatthew Dillon 	switch (AH_PRIVATE(ah)->ah_analog5GhzRev & AR_RADIO_SREV_MAJOR) {
402572ff6f6SMatthew Dillon         case AR_RAD5122_SREV_MAJOR:	/* Fowl: 5G/2x2 */
403572ff6f6SMatthew Dillon         case AR_RAD2122_SREV_MAJOR:	/* Fowl: 2+5G/2x2 */
404572ff6f6SMatthew Dillon         case AR_RAD2133_SREV_MAJOR:	/* Fowl: 2G/3x3 */
405572ff6f6SMatthew Dillon 	case AR_RAD5133_SREV_MAJOR:	/* Fowl: 2+5G/3x3 */
406572ff6f6SMatthew Dillon 		break;
407572ff6f6SMatthew Dillon 	default:
408572ff6f6SMatthew Dillon 		if (AH_PRIVATE(ah)->ah_analog5GhzRev == 0) {
409572ff6f6SMatthew Dillon 			/*
410572ff6f6SMatthew Dillon 			 * When RF_Silen is used the analog chip is reset.
411572ff6f6SMatthew Dillon 			 * So when the system boots with radio switch off
412572ff6f6SMatthew Dillon 			 * the RF chip rev reads back as zero and we need
413572ff6f6SMatthew Dillon 			 * to use the mac+phy revs to set the radio rev.
414572ff6f6SMatthew Dillon 			 */
415572ff6f6SMatthew Dillon 			AH_PRIVATE(ah)->ah_analog5GhzRev =
416572ff6f6SMatthew Dillon 				AR_RAD5133_SREV_MAJOR;
417572ff6f6SMatthew Dillon 			break;
418572ff6f6SMatthew Dillon 		}
419572ff6f6SMatthew Dillon 		/* NB: silently accept anything in release code per Atheros */
420572ff6f6SMatthew Dillon #ifdef AH_DEBUG
421572ff6f6SMatthew Dillon 		HALDEBUG(ah, HAL_DEBUG_ANY,
422572ff6f6SMatthew Dillon 		    "%s: 5G Radio Chip Rev 0x%02X is not supported by "
423572ff6f6SMatthew Dillon 		    "this driver\n", __func__,
424572ff6f6SMatthew Dillon 		    AH_PRIVATE(ah)->ah_analog5GhzRev);
425572ff6f6SMatthew Dillon 		ecode = HAL_ENOTSUPP;
426572ff6f6SMatthew Dillon 		goto bad;
427572ff6f6SMatthew Dillon #endif
428572ff6f6SMatthew Dillon 	}
429572ff6f6SMatthew Dillon 
430572ff6f6SMatthew Dillon 	/*
431572ff6f6SMatthew Dillon 	 * Got everything we need now to setup the capabilities.
432572ff6f6SMatthew Dillon 	 */
433572ff6f6SMatthew Dillon 	if (!ar5416FillCapabilityInfo(ah)) {
434572ff6f6SMatthew Dillon 		ecode = HAL_EEREAD;
435572ff6f6SMatthew Dillon 		goto bad;
436572ff6f6SMatthew Dillon 	}
437572ff6f6SMatthew Dillon 
438572ff6f6SMatthew Dillon 	ecode = ath_hal_eepromGet(ah, AR_EEP_MACADDR, ahp->ah_macaddr);
439572ff6f6SMatthew Dillon 	if (ecode != HAL_OK) {
440572ff6f6SMatthew Dillon 		HALDEBUG(ah, HAL_DEBUG_ANY,
441572ff6f6SMatthew Dillon 		    "%s: error getting mac address from EEPROM\n", __func__);
442572ff6f6SMatthew Dillon 		goto bad;
443572ff6f6SMatthew Dillon         }
444572ff6f6SMatthew Dillon 	/* XXX How about the serial number ? */
445572ff6f6SMatthew Dillon 	/* Read Reg Domain */
446572ff6f6SMatthew Dillon 	AH_PRIVATE(ah)->ah_currentRD =
447572ff6f6SMatthew Dillon 	    ath_hal_eepromGet(ah, AR_EEP_REGDMN_0, AH_NULL);
448572ff6f6SMatthew Dillon 	AH_PRIVATE(ah)->ah_currentRDext =
449572ff6f6SMatthew Dillon 	    ath_hal_eepromGet(ah, AR_EEP_REGDMN_1, AH_NULL);
450572ff6f6SMatthew Dillon 
451572ff6f6SMatthew Dillon 	/*
452572ff6f6SMatthew Dillon 	 * ah_miscMode is populated by ar5416FillCapabilityInfo()
453572ff6f6SMatthew Dillon 	 * starting from griffin. Set here to make sure that
454572ff6f6SMatthew Dillon 	 * AR_MISC_MODE_MIC_NEW_LOC_ENABLE is set before a GTK is
455572ff6f6SMatthew Dillon 	 * placed into hardware.
456572ff6f6SMatthew Dillon 	 */
457572ff6f6SMatthew Dillon 	if (ahp->ah_miscMode != 0)
458572ff6f6SMatthew Dillon 		OS_REG_WRITE(ah, AR_MISC_MODE, OS_REG_READ(ah, AR_MISC_MODE) | ahp->ah_miscMode);
459572ff6f6SMatthew Dillon 
460572ff6f6SMatthew Dillon 	rfStatus = ar2133RfAttach(ah, &ecode);
461572ff6f6SMatthew Dillon 	if (!rfStatus) {
462572ff6f6SMatthew Dillon 		HALDEBUG(ah, HAL_DEBUG_ANY, "%s: RF setup failed, status %u\n",
463572ff6f6SMatthew Dillon 		    __func__, ecode);
464572ff6f6SMatthew Dillon 		goto bad;
465572ff6f6SMatthew Dillon 	}
466572ff6f6SMatthew Dillon 
467572ff6f6SMatthew Dillon 	ar5416AniSetup(ah);			/* Anti Noise Immunity */
468572ff6f6SMatthew Dillon 
469572ff6f6SMatthew Dillon 	AH5416(ah)->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_5416_2GHZ;
470572ff6f6SMatthew Dillon 	AH5416(ah)->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_5416_2GHZ;
471572ff6f6SMatthew Dillon 	AH5416(ah)->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_5416_2GHZ;
472572ff6f6SMatthew Dillon 	AH5416(ah)->nf_5g.max = AR_PHY_CCA_MAX_GOOD_VAL_5416_5GHZ;
473572ff6f6SMatthew Dillon 	AH5416(ah)->nf_5g.min = AR_PHY_CCA_MIN_GOOD_VAL_5416_5GHZ;
474572ff6f6SMatthew Dillon 	AH5416(ah)->nf_5g.nominal = AR_PHY_CCA_NOM_VAL_5416_5GHZ;
475572ff6f6SMatthew Dillon 
476572ff6f6SMatthew Dillon 	ar5416InitNfHistBuff(AH5416(ah)->ah_cal.nfCalHist);
477572ff6f6SMatthew Dillon 
478572ff6f6SMatthew Dillon 	HALDEBUG(ah, HAL_DEBUG_ATTACH, "%s: return\n", __func__);
479572ff6f6SMatthew Dillon 
480572ff6f6SMatthew Dillon 	return ah;
481572ff6f6SMatthew Dillon bad:
482572ff6f6SMatthew Dillon 	if (ahp)
483572ff6f6SMatthew Dillon 		ar5416Detach((struct ath_hal *) ahp);
484572ff6f6SMatthew Dillon 	if (status)
485572ff6f6SMatthew Dillon 		*status = ecode;
486572ff6f6SMatthew Dillon 	return AH_NULL;
487572ff6f6SMatthew Dillon }
488572ff6f6SMatthew Dillon 
489572ff6f6SMatthew Dillon void
ar5416Detach(struct ath_hal * ah)490572ff6f6SMatthew Dillon ar5416Detach(struct ath_hal *ah)
491572ff6f6SMatthew Dillon {
492572ff6f6SMatthew Dillon 	HALDEBUG(ah, HAL_DEBUG_ATTACH, "%s:\n", __func__);
493572ff6f6SMatthew Dillon 
494572ff6f6SMatthew Dillon 	HALASSERT(ah != AH_NULL);
495572ff6f6SMatthew Dillon 	HALASSERT(ah->ah_magic == AR5416_MAGIC);
496572ff6f6SMatthew Dillon 
497572ff6f6SMatthew Dillon 	/* Make sure that chip is awake before writing to it */
498572ff6f6SMatthew Dillon 	if (! ar5416SetPowerMode(ah, HAL_PM_AWAKE, AH_TRUE))
499572ff6f6SMatthew Dillon 		HALDEBUG(ah, HAL_DEBUG_UNMASKABLE,
500572ff6f6SMatthew Dillon 		    "%s: failed to wake up chip\n",
501572ff6f6SMatthew Dillon 		    __func__);
502572ff6f6SMatthew Dillon 
503572ff6f6SMatthew Dillon 	ar5416AniDetach(ah);
504572ff6f6SMatthew Dillon 	ar5212RfDetach(ah);
505572ff6f6SMatthew Dillon 	ah->ah_disable(ah);
506572ff6f6SMatthew Dillon 	ar5416SetPowerMode(ah, HAL_PM_FULL_SLEEP, AH_TRUE);
507572ff6f6SMatthew Dillon 	ath_hal_eepromDetach(ah);
508572ff6f6SMatthew Dillon 	ath_hal_free(ah);
509572ff6f6SMatthew Dillon }
510572ff6f6SMatthew Dillon 
511572ff6f6SMatthew Dillon void
ar5416AttachPCIE(struct ath_hal * ah)512572ff6f6SMatthew Dillon ar5416AttachPCIE(struct ath_hal *ah)
513572ff6f6SMatthew Dillon {
514572ff6f6SMatthew Dillon 	if (AH_PRIVATE(ah)->ah_ispcie)
515572ff6f6SMatthew Dillon 		ath_hal_configPCIE(ah, AH_FALSE, AH_FALSE);
516572ff6f6SMatthew Dillon 	else
517572ff6f6SMatthew Dillon 		ath_hal_disablePCIE(ah);
518572ff6f6SMatthew Dillon }
519572ff6f6SMatthew Dillon 
520572ff6f6SMatthew Dillon static void
ar5416ConfigPCIE(struct ath_hal * ah,HAL_BOOL restore,HAL_BOOL power_off)521572ff6f6SMatthew Dillon ar5416ConfigPCIE(struct ath_hal *ah, HAL_BOOL restore, HAL_BOOL power_off)
522572ff6f6SMatthew Dillon {
523572ff6f6SMatthew Dillon 
524572ff6f6SMatthew Dillon 	/* This is only applicable for AR5418 (AR5416 PCIe) */
525572ff6f6SMatthew Dillon 	if (! AH_PRIVATE(ah)->ah_ispcie)
526572ff6f6SMatthew Dillon 		return;
527572ff6f6SMatthew Dillon 
528572ff6f6SMatthew Dillon 	if (! restore) {
529572ff6f6SMatthew Dillon 		ath_hal_ini_write(ah, &AH5416(ah)->ah_ini_pcieserdes, 1, 0);
530572ff6f6SMatthew Dillon 		OS_DELAY(1000);
531572ff6f6SMatthew Dillon 	}
532572ff6f6SMatthew Dillon 
533572ff6f6SMatthew Dillon 	if (power_off) {		/* Power-off */
534572ff6f6SMatthew Dillon 		/* clear bit 19 to disable L1 */
535572ff6f6SMatthew Dillon 		OS_REG_CLR_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
536572ff6f6SMatthew Dillon 	} else {			/* Power-on */
537572ff6f6SMatthew Dillon 		/* Set default WAR values for Owl */
538572ff6f6SMatthew Dillon 		OS_REG_WRITE(ah, AR_WA, AR_WA_DEFAULT);
539572ff6f6SMatthew Dillon 
540572ff6f6SMatthew Dillon 		/* set bit 19 to allow forcing of pcie core into L1 state */
541572ff6f6SMatthew Dillon 		OS_REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
542572ff6f6SMatthew Dillon 	}
543572ff6f6SMatthew Dillon }
544572ff6f6SMatthew Dillon 
545572ff6f6SMatthew Dillon /*
546572ff6f6SMatthew Dillon  * Disable PCIe PHY if PCIe isn't used.
547572ff6f6SMatthew Dillon  */
548572ff6f6SMatthew Dillon static void
ar5416DisablePCIE(struct ath_hal * ah)549572ff6f6SMatthew Dillon ar5416DisablePCIE(struct ath_hal *ah)
550572ff6f6SMatthew Dillon {
551572ff6f6SMatthew Dillon 
552572ff6f6SMatthew Dillon 	/* PCIe? Don't */
553572ff6f6SMatthew Dillon 	if (AH_PRIVATE(ah)->ah_ispcie)
554572ff6f6SMatthew Dillon 		return;
555572ff6f6SMatthew Dillon 
556572ff6f6SMatthew Dillon 	/* .. Only applicable for AR5416v2 or later */
557572ff6f6SMatthew Dillon 	if (! (AR_SREV_OWL(ah) && AR_SREV_OWL_20_OR_LATER(ah)))
558572ff6f6SMatthew Dillon 		return;
559572ff6f6SMatthew Dillon 
560572ff6f6SMatthew Dillon 	OS_REG_WRITE_BUFFER_ENABLE(ah);
561572ff6f6SMatthew Dillon 
562572ff6f6SMatthew Dillon 	/*
563572ff6f6SMatthew Dillon 	 * Disable the PCIe PHY.
564572ff6f6SMatthew Dillon 	 */
565572ff6f6SMatthew Dillon 	OS_REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
566572ff6f6SMatthew Dillon 	OS_REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
567572ff6f6SMatthew Dillon 	OS_REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
568572ff6f6SMatthew Dillon 	OS_REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
569572ff6f6SMatthew Dillon 	OS_REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
570572ff6f6SMatthew Dillon 	OS_REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
571572ff6f6SMatthew Dillon 	OS_REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
572572ff6f6SMatthew Dillon 	OS_REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
573572ff6f6SMatthew Dillon 	OS_REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
574572ff6f6SMatthew Dillon 
575572ff6f6SMatthew Dillon 	/* Load the new settings */
576572ff6f6SMatthew Dillon 	OS_REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
577572ff6f6SMatthew Dillon 
578572ff6f6SMatthew Dillon 	OS_REG_WRITE_BUFFER_FLUSH(ah);
579572ff6f6SMatthew Dillon 	OS_REG_WRITE_BUFFER_DISABLE(ah);
580572ff6f6SMatthew Dillon }
581572ff6f6SMatthew Dillon 
582572ff6f6SMatthew Dillon static void
ar5416WriteIni(struct ath_hal * ah,const struct ieee80211_channel * chan)583572ff6f6SMatthew Dillon ar5416WriteIni(struct ath_hal *ah, const struct ieee80211_channel *chan)
584572ff6f6SMatthew Dillon {
585572ff6f6SMatthew Dillon 	u_int modesIndex, freqIndex;
586572ff6f6SMatthew Dillon 	int regWrites = 0;
587572ff6f6SMatthew Dillon 
588572ff6f6SMatthew Dillon 	/* Setup the indices for the next set of register array writes */
589572ff6f6SMatthew Dillon 	/* XXX Ignore 11n dynamic mode on the AR5416 for the moment */
590572ff6f6SMatthew Dillon 	if (IEEE80211_IS_CHAN_2GHZ(chan)) {
591572ff6f6SMatthew Dillon 		freqIndex = 2;
592572ff6f6SMatthew Dillon 		if (IEEE80211_IS_CHAN_HT40(chan))
593572ff6f6SMatthew Dillon 			modesIndex = 3;
594572ff6f6SMatthew Dillon 		else if (IEEE80211_IS_CHAN_108G(chan))
595572ff6f6SMatthew Dillon 			modesIndex = 5;
596572ff6f6SMatthew Dillon 		else
597572ff6f6SMatthew Dillon 			modesIndex = 4;
598572ff6f6SMatthew Dillon 	} else {
599572ff6f6SMatthew Dillon 		freqIndex = 1;
600572ff6f6SMatthew Dillon 		if (IEEE80211_IS_CHAN_HT40(chan) ||
601572ff6f6SMatthew Dillon 		    IEEE80211_IS_CHAN_TURBO(chan))
602572ff6f6SMatthew Dillon 			modesIndex = 2;
603572ff6f6SMatthew Dillon 		else
604572ff6f6SMatthew Dillon 			modesIndex = 1;
605572ff6f6SMatthew Dillon 	}
606572ff6f6SMatthew Dillon 
607572ff6f6SMatthew Dillon 	/* Set correct Baseband to analog shift setting to access analog chips. */
608572ff6f6SMatthew Dillon 	OS_REG_WRITE(ah, AR_PHY(0), 0x00000007);
609572ff6f6SMatthew Dillon 
610572ff6f6SMatthew Dillon 	/*
611572ff6f6SMatthew Dillon 	 * Write addac shifts
612572ff6f6SMatthew Dillon 	 */
613572ff6f6SMatthew Dillon 	OS_REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_EXTERNAL_RADIO);
614572ff6f6SMatthew Dillon 
615572ff6f6SMatthew Dillon 	/* NB: only required for Sowl */
616572ff6f6SMatthew Dillon 	if (AR_SREV_SOWL(ah))
617572ff6f6SMatthew Dillon 		ar5416EepromSetAddac(ah, chan);
618572ff6f6SMatthew Dillon 
619572ff6f6SMatthew Dillon 	regWrites = ath_hal_ini_write(ah, &AH5416(ah)->ah_ini_addac, 1,
620572ff6f6SMatthew Dillon 	    regWrites);
621572ff6f6SMatthew Dillon 	OS_REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC);
622572ff6f6SMatthew Dillon 
623572ff6f6SMatthew Dillon 	regWrites = ath_hal_ini_write(ah, &AH5212(ah)->ah_ini_modes,
624572ff6f6SMatthew Dillon 	    modesIndex, regWrites);
625572ff6f6SMatthew Dillon 	regWrites = ath_hal_ini_write(ah, &AH5212(ah)->ah_ini_common,
626572ff6f6SMatthew Dillon 	    1, regWrites);
627572ff6f6SMatthew Dillon 
628572ff6f6SMatthew Dillon 	/* XXX updated regWrites? */
629572ff6f6SMatthew Dillon 	AH5212(ah)->ah_rfHal->writeRegs(ah, modesIndex, freqIndex, regWrites);
630572ff6f6SMatthew Dillon }
631572ff6f6SMatthew Dillon 
632572ff6f6SMatthew Dillon /*
633572ff6f6SMatthew Dillon  * Convert to baseband spur frequency given input channel frequency
634572ff6f6SMatthew Dillon  * and compute register settings below.
635572ff6f6SMatthew Dillon  */
636572ff6f6SMatthew Dillon 
637572ff6f6SMatthew Dillon static void
ar5416SpurMitigate(struct ath_hal * ah,const struct ieee80211_channel * chan)638572ff6f6SMatthew Dillon ar5416SpurMitigate(struct ath_hal *ah, const struct ieee80211_channel *chan)
639572ff6f6SMatthew Dillon {
640572ff6f6SMatthew Dillon     uint16_t freq = ath_hal_gethwchannel(ah, chan);
641572ff6f6SMatthew Dillon     static const int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
642572ff6f6SMatthew Dillon                 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60 };
643572ff6f6SMatthew Dillon     static const int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
644572ff6f6SMatthew Dillon                 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60 };
645572ff6f6SMatthew Dillon     static const int inc[4] = { 0, 100, 0, 0 };
646572ff6f6SMatthew Dillon 
647572ff6f6SMatthew Dillon     int bb_spur = AR_NO_SPUR;
648572ff6f6SMatthew Dillon     int bin, cur_bin;
649572ff6f6SMatthew Dillon     int spur_freq_sd;
650572ff6f6SMatthew Dillon     int spur_delta_phase;
651572ff6f6SMatthew Dillon     int denominator;
652572ff6f6SMatthew Dillon     int upper, lower, cur_vit_mask;
653572ff6f6SMatthew Dillon     int tmp, new;
654572ff6f6SMatthew Dillon     int i;
655572ff6f6SMatthew Dillon 
656572ff6f6SMatthew Dillon     int8_t mask_m[123];
657572ff6f6SMatthew Dillon     int8_t mask_p[123];
658572ff6f6SMatthew Dillon     int8_t mask_amt;
659572ff6f6SMatthew Dillon     int tmp_mask;
660572ff6f6SMatthew Dillon     int cur_bb_spur;
661572ff6f6SMatthew Dillon     HAL_BOOL is2GHz = IEEE80211_IS_CHAN_2GHZ(chan);
662572ff6f6SMatthew Dillon 
663572ff6f6SMatthew Dillon     OS_MEMZERO(mask_m, sizeof(mask_m));
664572ff6f6SMatthew Dillon     OS_MEMZERO(mask_p, sizeof(mask_p));
665572ff6f6SMatthew Dillon 
666572ff6f6SMatthew Dillon     /*
667572ff6f6SMatthew Dillon      * Need to verify range +/- 9.5 for static ht20, otherwise spur
668572ff6f6SMatthew Dillon      * is out-of-band and can be ignored.
669572ff6f6SMatthew Dillon      */
670572ff6f6SMatthew Dillon     /* XXX ath9k changes */
671572ff6f6SMatthew Dillon     for (i = 0; i < AR5416_EEPROM_MODAL_SPURS; i++) {
672572ff6f6SMatthew Dillon         cur_bb_spur = ath_hal_getSpurChan(ah, i, is2GHz);
673572ff6f6SMatthew Dillon         if (AR_NO_SPUR == cur_bb_spur)
674572ff6f6SMatthew Dillon             break;
675572ff6f6SMatthew Dillon         cur_bb_spur = cur_bb_spur - (freq * 10);
676572ff6f6SMatthew Dillon         if ((cur_bb_spur > -95) && (cur_bb_spur < 95)) {
677572ff6f6SMatthew Dillon             bb_spur = cur_bb_spur;
678572ff6f6SMatthew Dillon             break;
679572ff6f6SMatthew Dillon         }
680572ff6f6SMatthew Dillon     }
681572ff6f6SMatthew Dillon     if (AR_NO_SPUR == bb_spur)
682572ff6f6SMatthew Dillon         return;
683572ff6f6SMatthew Dillon 
684572ff6f6SMatthew Dillon     bin = bb_spur * 32;
685572ff6f6SMatthew Dillon 
686572ff6f6SMatthew Dillon     tmp = OS_REG_READ(ah, AR_PHY_TIMING_CTRL4_CHAIN(0));
687572ff6f6SMatthew Dillon     new = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
688572ff6f6SMatthew Dillon         AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
689572ff6f6SMatthew Dillon         AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
690572ff6f6SMatthew Dillon         AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
691572ff6f6SMatthew Dillon 
692572ff6f6SMatthew Dillon     OS_REG_WRITE_BUFFER_ENABLE(ah);
693572ff6f6SMatthew Dillon 
694572ff6f6SMatthew Dillon     OS_REG_WRITE(ah, AR_PHY_TIMING_CTRL4_CHAIN(0), new);
695572ff6f6SMatthew Dillon 
696572ff6f6SMatthew Dillon     new = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
697572ff6f6SMatthew Dillon         AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
698572ff6f6SMatthew Dillon         AR_PHY_SPUR_REG_MASK_RATE_SELECT |
699572ff6f6SMatthew Dillon         AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
700572ff6f6SMatthew Dillon         SM(AR5416_SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
701572ff6f6SMatthew Dillon     OS_REG_WRITE(ah, AR_PHY_SPUR_REG, new);
702572ff6f6SMatthew Dillon     /*
703572ff6f6SMatthew Dillon      * Should offset bb_spur by +/- 10 MHz for dynamic 2040 MHz
704572ff6f6SMatthew Dillon      * config, no offset for HT20.
705572ff6f6SMatthew Dillon      * spur_delta_phase = bb_spur/40 * 2**21 for static ht20,
706572ff6f6SMatthew Dillon      * /80 for dyn2040.
707572ff6f6SMatthew Dillon      */
708572ff6f6SMatthew Dillon     spur_delta_phase = ((bb_spur * 524288) / 100) &
709572ff6f6SMatthew Dillon         AR_PHY_TIMING11_SPUR_DELTA_PHASE;
710572ff6f6SMatthew Dillon     /*
711572ff6f6SMatthew Dillon      * in 11A mode the denominator of spur_freq_sd should be 40 and
712572ff6f6SMatthew Dillon      * it should be 44 in 11G
713572ff6f6SMatthew Dillon      */
714572ff6f6SMatthew Dillon     denominator = IEEE80211_IS_CHAN_2GHZ(chan) ? 440 : 400;
715572ff6f6SMatthew Dillon     spur_freq_sd = ((bb_spur * 2048) / denominator) & 0x3ff;
716572ff6f6SMatthew Dillon 
717572ff6f6SMatthew Dillon     new = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
718572ff6f6SMatthew Dillon         SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
719572ff6f6SMatthew Dillon         SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
720572ff6f6SMatthew Dillon     OS_REG_WRITE(ah, AR_PHY_TIMING11, new);
721572ff6f6SMatthew Dillon 
722572ff6f6SMatthew Dillon 
723572ff6f6SMatthew Dillon     /*
724572ff6f6SMatthew Dillon      * ============================================
725572ff6f6SMatthew Dillon      * pilot mask 1 [31:0] = +6..-26, no 0 bin
726572ff6f6SMatthew Dillon      * pilot mask 2 [19:0] = +26..+7
727572ff6f6SMatthew Dillon      *
728572ff6f6SMatthew Dillon      * channel mask 1 [31:0] = +6..-26, no 0 bin
729572ff6f6SMatthew Dillon      * channel mask 2 [19:0] = +26..+7
730572ff6f6SMatthew Dillon      */
731572ff6f6SMatthew Dillon     //cur_bin = -26;
732572ff6f6SMatthew Dillon     cur_bin = -6000;
733572ff6f6SMatthew Dillon     upper = bin + 100;
734572ff6f6SMatthew Dillon     lower = bin - 100;
735572ff6f6SMatthew Dillon 
736572ff6f6SMatthew Dillon     for (i = 0; i < 4; i++) {
737572ff6f6SMatthew Dillon         int pilot_mask = 0;
738572ff6f6SMatthew Dillon         int chan_mask  = 0;
739572ff6f6SMatthew Dillon         int bp         = 0;
740572ff6f6SMatthew Dillon         for (bp = 0; bp < 30; bp++) {
741572ff6f6SMatthew Dillon             if ((cur_bin > lower) && (cur_bin < upper)) {
742572ff6f6SMatthew Dillon                 pilot_mask = pilot_mask | 0x1 << bp;
743572ff6f6SMatthew Dillon                 chan_mask  = chan_mask | 0x1 << bp;
744572ff6f6SMatthew Dillon             }
745572ff6f6SMatthew Dillon             cur_bin += 100;
746572ff6f6SMatthew Dillon         }
747572ff6f6SMatthew Dillon         cur_bin += inc[i];
748572ff6f6SMatthew Dillon         OS_REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
749572ff6f6SMatthew Dillon         OS_REG_WRITE(ah, chan_mask_reg[i], chan_mask);
750572ff6f6SMatthew Dillon     }
751572ff6f6SMatthew Dillon 
752572ff6f6SMatthew Dillon     /* =================================================
753572ff6f6SMatthew Dillon      * viterbi mask 1 based on channel magnitude
754572ff6f6SMatthew Dillon      * four levels 0-3
755572ff6f6SMatthew Dillon      *  - mask (-27 to 27) (reg 64,0x9900 to 67,0x990c)
756572ff6f6SMatthew Dillon      *      [1 2 2 1] for -9.6 or [1 2 1] for +16
757572ff6f6SMatthew Dillon      *  - enable_mask_ppm, all bins move with freq
758572ff6f6SMatthew Dillon      *
759572ff6f6SMatthew Dillon      *  - mask_select,    8 bits for rates (reg 67,0x990c)
760572ff6f6SMatthew Dillon      *  - mask_rate_cntl, 8 bits for rates (reg 67,0x990c)
761572ff6f6SMatthew Dillon      *      choose which mask to use mask or mask2
762572ff6f6SMatthew Dillon      */
763572ff6f6SMatthew Dillon 
764572ff6f6SMatthew Dillon     /*
765572ff6f6SMatthew Dillon      * viterbi mask 2  2nd set for per data rate puncturing
766572ff6f6SMatthew Dillon      * four levels 0-3
767572ff6f6SMatthew Dillon      *  - mask_select, 8 bits for rates (reg 67)
768572ff6f6SMatthew Dillon      *  - mask (-27 to 27) (reg 98,0x9988 to 101,0x9994)
769572ff6f6SMatthew Dillon      *      [1 2 2 1] for -9.6 or [1 2 1] for +16
770572ff6f6SMatthew Dillon      */
771572ff6f6SMatthew Dillon     cur_vit_mask = 6100;
772572ff6f6SMatthew Dillon     upper        = bin + 120;
773572ff6f6SMatthew Dillon     lower        = bin - 120;
774572ff6f6SMatthew Dillon 
775572ff6f6SMatthew Dillon     for (i = 0; i < 123; i++) {
776572ff6f6SMatthew Dillon         if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
777572ff6f6SMatthew Dillon             if ((abs(cur_vit_mask - bin)) < 75) {
778572ff6f6SMatthew Dillon                 mask_amt = 1;
779572ff6f6SMatthew Dillon             } else {
780572ff6f6SMatthew Dillon                 mask_amt = 0;
781572ff6f6SMatthew Dillon             }
782572ff6f6SMatthew Dillon             if (cur_vit_mask < 0) {
783572ff6f6SMatthew Dillon                 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
784572ff6f6SMatthew Dillon             } else {
785572ff6f6SMatthew Dillon                 mask_p[cur_vit_mask / 100] = mask_amt;
786572ff6f6SMatthew Dillon             }
787572ff6f6SMatthew Dillon         }
788572ff6f6SMatthew Dillon         cur_vit_mask -= 100;
789572ff6f6SMatthew Dillon     }
790572ff6f6SMatthew Dillon 
791572ff6f6SMatthew Dillon     tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
792572ff6f6SMatthew Dillon           | (mask_m[48] << 26) | (mask_m[49] << 24)
793572ff6f6SMatthew Dillon           | (mask_m[50] << 22) | (mask_m[51] << 20)
794572ff6f6SMatthew Dillon           | (mask_m[52] << 18) | (mask_m[53] << 16)
795572ff6f6SMatthew Dillon           | (mask_m[54] << 14) | (mask_m[55] << 12)
796572ff6f6SMatthew Dillon           | (mask_m[56] << 10) | (mask_m[57] <<  8)
797572ff6f6SMatthew Dillon           | (mask_m[58] <<  6) | (mask_m[59] <<  4)
798572ff6f6SMatthew Dillon           | (mask_m[60] <<  2) | (mask_m[61] <<  0);
799572ff6f6SMatthew Dillon     OS_REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
800572ff6f6SMatthew Dillon     OS_REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
801572ff6f6SMatthew Dillon 
802572ff6f6SMatthew Dillon     tmp_mask =             (mask_m[31] << 28)
803572ff6f6SMatthew Dillon           | (mask_m[32] << 26) | (mask_m[33] << 24)
804572ff6f6SMatthew Dillon           | (mask_m[34] << 22) | (mask_m[35] << 20)
805572ff6f6SMatthew Dillon           | (mask_m[36] << 18) | (mask_m[37] << 16)
806572ff6f6SMatthew Dillon           | (mask_m[48] << 14) | (mask_m[39] << 12)
807572ff6f6SMatthew Dillon           | (mask_m[40] << 10) | (mask_m[41] <<  8)
808572ff6f6SMatthew Dillon           | (mask_m[42] <<  6) | (mask_m[43] <<  4)
809572ff6f6SMatthew Dillon           | (mask_m[44] <<  2) | (mask_m[45] <<  0);
810572ff6f6SMatthew Dillon     OS_REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
811572ff6f6SMatthew Dillon     OS_REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
812572ff6f6SMatthew Dillon 
813572ff6f6SMatthew Dillon     tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
814572ff6f6SMatthew Dillon           | (mask_m[18] << 26) | (mask_m[18] << 24)
815572ff6f6SMatthew Dillon           | (mask_m[20] << 22) | (mask_m[20] << 20)
816572ff6f6SMatthew Dillon           | (mask_m[22] << 18) | (mask_m[22] << 16)
817572ff6f6SMatthew Dillon           | (mask_m[24] << 14) | (mask_m[24] << 12)
818572ff6f6SMatthew Dillon           | (mask_m[25] << 10) | (mask_m[26] <<  8)
819572ff6f6SMatthew Dillon           | (mask_m[27] <<  6) | (mask_m[28] <<  4)
820572ff6f6SMatthew Dillon           | (mask_m[29] <<  2) | (mask_m[30] <<  0);
821572ff6f6SMatthew Dillon     OS_REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
822572ff6f6SMatthew Dillon     OS_REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
823572ff6f6SMatthew Dillon 
824572ff6f6SMatthew Dillon     tmp_mask = (mask_m[ 0] << 30) | (mask_m[ 1] << 28)
825572ff6f6SMatthew Dillon           | (mask_m[ 2] << 26) | (mask_m[ 3] << 24)
826572ff6f6SMatthew Dillon           | (mask_m[ 4] << 22) | (mask_m[ 5] << 20)
827572ff6f6SMatthew Dillon           | (mask_m[ 6] << 18) | (mask_m[ 7] << 16)
828572ff6f6SMatthew Dillon           | (mask_m[ 8] << 14) | (mask_m[ 9] << 12)
829572ff6f6SMatthew Dillon           | (mask_m[10] << 10) | (mask_m[11] <<  8)
830572ff6f6SMatthew Dillon           | (mask_m[12] <<  6) | (mask_m[13] <<  4)
831572ff6f6SMatthew Dillon           | (mask_m[14] <<  2) | (mask_m[15] <<  0);
832572ff6f6SMatthew Dillon     OS_REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
833572ff6f6SMatthew Dillon     OS_REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
834572ff6f6SMatthew Dillon 
835572ff6f6SMatthew Dillon     tmp_mask =             (mask_p[15] << 28)
836572ff6f6SMatthew Dillon           | (mask_p[14] << 26) | (mask_p[13] << 24)
837572ff6f6SMatthew Dillon           | (mask_p[12] << 22) | (mask_p[11] << 20)
838572ff6f6SMatthew Dillon           | (mask_p[10] << 18) | (mask_p[ 9] << 16)
839572ff6f6SMatthew Dillon           | (mask_p[ 8] << 14) | (mask_p[ 7] << 12)
840572ff6f6SMatthew Dillon           | (mask_p[ 6] << 10) | (mask_p[ 5] <<  8)
841572ff6f6SMatthew Dillon           | (mask_p[ 4] <<  6) | (mask_p[ 3] <<  4)
842572ff6f6SMatthew Dillon           | (mask_p[ 2] <<  2) | (mask_p[ 1] <<  0);
843572ff6f6SMatthew Dillon     OS_REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
844572ff6f6SMatthew Dillon     OS_REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
845572ff6f6SMatthew Dillon 
846572ff6f6SMatthew Dillon     tmp_mask =             (mask_p[30] << 28)
847572ff6f6SMatthew Dillon           | (mask_p[29] << 26) | (mask_p[28] << 24)
848572ff6f6SMatthew Dillon           | (mask_p[27] << 22) | (mask_p[26] << 20)
849572ff6f6SMatthew Dillon           | (mask_p[25] << 18) | (mask_p[24] << 16)
850572ff6f6SMatthew Dillon           | (mask_p[23] << 14) | (mask_p[22] << 12)
851572ff6f6SMatthew Dillon           | (mask_p[21] << 10) | (mask_p[20] <<  8)
852572ff6f6SMatthew Dillon           | (mask_p[19] <<  6) | (mask_p[18] <<  4)
853572ff6f6SMatthew Dillon           | (mask_p[17] <<  2) | (mask_p[16] <<  0);
854572ff6f6SMatthew Dillon     OS_REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
855572ff6f6SMatthew Dillon     OS_REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
856572ff6f6SMatthew Dillon 
857572ff6f6SMatthew Dillon     tmp_mask =             (mask_p[45] << 28)
858572ff6f6SMatthew Dillon           | (mask_p[44] << 26) | (mask_p[43] << 24)
859572ff6f6SMatthew Dillon           | (mask_p[42] << 22) | (mask_p[41] << 20)
860572ff6f6SMatthew Dillon           | (mask_p[40] << 18) | (mask_p[39] << 16)
861572ff6f6SMatthew Dillon           | (mask_p[38] << 14) | (mask_p[37] << 12)
862572ff6f6SMatthew Dillon           | (mask_p[36] << 10) | (mask_p[35] <<  8)
863572ff6f6SMatthew Dillon           | (mask_p[34] <<  6) | (mask_p[33] <<  4)
864572ff6f6SMatthew Dillon           | (mask_p[32] <<  2) | (mask_p[31] <<  0);
865572ff6f6SMatthew Dillon     OS_REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
866572ff6f6SMatthew Dillon     OS_REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
867572ff6f6SMatthew Dillon 
868572ff6f6SMatthew Dillon     tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
869572ff6f6SMatthew Dillon           | (mask_p[59] << 26) | (mask_p[58] << 24)
870572ff6f6SMatthew Dillon           | (mask_p[57] << 22) | (mask_p[56] << 20)
871572ff6f6SMatthew Dillon           | (mask_p[55] << 18) | (mask_p[54] << 16)
872572ff6f6SMatthew Dillon           | (mask_p[53] << 14) | (mask_p[52] << 12)
873572ff6f6SMatthew Dillon           | (mask_p[51] << 10) | (mask_p[50] <<  8)
874572ff6f6SMatthew Dillon           | (mask_p[49] <<  6) | (mask_p[48] <<  4)
875572ff6f6SMatthew Dillon           | (mask_p[47] <<  2) | (mask_p[46] <<  0);
876572ff6f6SMatthew Dillon     OS_REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
877572ff6f6SMatthew Dillon     OS_REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
878572ff6f6SMatthew Dillon 
879572ff6f6SMatthew Dillon     OS_REG_WRITE_BUFFER_FLUSH(ah);
880572ff6f6SMatthew Dillon     OS_REG_WRITE_BUFFER_DISABLE(ah);
881572ff6f6SMatthew Dillon }
882572ff6f6SMatthew Dillon 
883572ff6f6SMatthew Dillon /*
884572ff6f6SMatthew Dillon  * Fill all software cached or static hardware state information.
885572ff6f6SMatthew Dillon  * Return failure if capabilities are to come from EEPROM and
886572ff6f6SMatthew Dillon  * cannot be read.
887572ff6f6SMatthew Dillon  */
888572ff6f6SMatthew Dillon HAL_BOOL
ar5416FillCapabilityInfo(struct ath_hal * ah)889572ff6f6SMatthew Dillon ar5416FillCapabilityInfo(struct ath_hal *ah)
890572ff6f6SMatthew Dillon {
891572ff6f6SMatthew Dillon 	struct ath_hal_private *ahpriv = AH_PRIVATE(ah);
892572ff6f6SMatthew Dillon 	HAL_CAPABILITIES *pCap = &ahpriv->ah_caps;
893572ff6f6SMatthew Dillon 	uint16_t val;
894572ff6f6SMatthew Dillon 
895572ff6f6SMatthew Dillon 	/* Construct wireless mode from EEPROM */
896572ff6f6SMatthew Dillon 	pCap->halWirelessModes = 0;
897572ff6f6SMatthew Dillon 	if (ath_hal_eepromGetFlag(ah, AR_EEP_AMODE)) {
898572ff6f6SMatthew Dillon 		pCap->halWirelessModes |= HAL_MODE_11A
899572ff6f6SMatthew Dillon 				       |  HAL_MODE_11NA_HT20
900572ff6f6SMatthew Dillon 				       |  HAL_MODE_11NA_HT40PLUS
901572ff6f6SMatthew Dillon 				       |  HAL_MODE_11NA_HT40MINUS
902572ff6f6SMatthew Dillon 				       ;
903572ff6f6SMatthew Dillon 	}
904572ff6f6SMatthew Dillon 	if (ath_hal_eepromGetFlag(ah, AR_EEP_GMODE)) {
905572ff6f6SMatthew Dillon 		pCap->halWirelessModes |= HAL_MODE_11G
906572ff6f6SMatthew Dillon 				       |  HAL_MODE_11NG_HT20
907572ff6f6SMatthew Dillon 				       |  HAL_MODE_11NG_HT40PLUS
908572ff6f6SMatthew Dillon 				       |  HAL_MODE_11NG_HT40MINUS
909572ff6f6SMatthew Dillon 				       ;
910572ff6f6SMatthew Dillon 		pCap->halWirelessModes |= HAL_MODE_11A
911572ff6f6SMatthew Dillon 				       |  HAL_MODE_11NA_HT20
912572ff6f6SMatthew Dillon 				       |  HAL_MODE_11NA_HT40PLUS
913572ff6f6SMatthew Dillon 				       |  HAL_MODE_11NA_HT40MINUS
914572ff6f6SMatthew Dillon 				       ;
915572ff6f6SMatthew Dillon 	}
916572ff6f6SMatthew Dillon 
917572ff6f6SMatthew Dillon 	pCap->halLow2GhzChan = 2312;
918572ff6f6SMatthew Dillon 	pCap->halHigh2GhzChan = 2732;
919572ff6f6SMatthew Dillon 
920572ff6f6SMatthew Dillon 	pCap->halLow5GhzChan = 4915;
921572ff6f6SMatthew Dillon 	pCap->halHigh5GhzChan = 6100;
922572ff6f6SMatthew Dillon 
923572ff6f6SMatthew Dillon 	pCap->halCipherCkipSupport = AH_FALSE;
924572ff6f6SMatthew Dillon 	pCap->halCipherTkipSupport = AH_TRUE;
925572ff6f6SMatthew Dillon 	pCap->halCipherAesCcmSupport = ath_hal_eepromGetFlag(ah, AR_EEP_AES);
926572ff6f6SMatthew Dillon 
927572ff6f6SMatthew Dillon 	pCap->halMicCkipSupport    = AH_FALSE;
928572ff6f6SMatthew Dillon 	pCap->halMicTkipSupport    = AH_TRUE;
929572ff6f6SMatthew Dillon 	pCap->halMicAesCcmSupport  = ath_hal_eepromGetFlag(ah, AR_EEP_AES);
930572ff6f6SMatthew Dillon 	/*
931572ff6f6SMatthew Dillon 	 * Starting with Griffin TX+RX mic keys can be combined
932572ff6f6SMatthew Dillon 	 * in one key cache slot.
933572ff6f6SMatthew Dillon 	 */
934572ff6f6SMatthew Dillon 	pCap->halTkipMicTxRxKeySupport = AH_TRUE;
935572ff6f6SMatthew Dillon 	pCap->halChanSpreadSupport = AH_TRUE;
936572ff6f6SMatthew Dillon 	pCap->halSleepAfterBeaconBroken = AH_TRUE;
937572ff6f6SMatthew Dillon 
938572ff6f6SMatthew Dillon 	pCap->halCompressSupport = AH_FALSE;
939572ff6f6SMatthew Dillon 	pCap->halBurstSupport = AH_TRUE;
940b14ca477SMatthew Dillon 	pCap->halFastFramesSupport = AH_TRUE;
941572ff6f6SMatthew Dillon 	pCap->halChapTuningSupport = AH_TRUE;
942572ff6f6SMatthew Dillon 	pCap->halTurboPrimeSupport = AH_TRUE;
943572ff6f6SMatthew Dillon 
944572ff6f6SMatthew Dillon 	pCap->halTurboGSupport = pCap->halWirelessModes & HAL_MODE_108G;
945572ff6f6SMatthew Dillon 
946572ff6f6SMatthew Dillon 	pCap->halPSPollBroken = AH_TRUE;	/* XXX fixed in later revs? */
947572ff6f6SMatthew Dillon 	pCap->halNumMRRetries = 4;		/* Hardware supports 4 MRR */
948572ff6f6SMatthew Dillon 	pCap->halNumTxMaps = 1;			/* Single TX ptr per descr */
949572ff6f6SMatthew Dillon 	pCap->halVEOLSupport = AH_TRUE;
950572ff6f6SMatthew Dillon 	pCap->halBssIdMaskSupport = AH_TRUE;
951572ff6f6SMatthew Dillon 	pCap->halMcastKeySrchSupport = AH_TRUE;	/* Works on AR5416 and later */
952572ff6f6SMatthew Dillon 	pCap->halTsfAddSupport = AH_TRUE;
953572ff6f6SMatthew Dillon 	pCap->hal4AddrAggrSupport = AH_FALSE;	/* Broken in Owl */
954572ff6f6SMatthew Dillon 	pCap->halSpectralScanSupport = AH_FALSE;	/* AR9280 and later */
955572ff6f6SMatthew Dillon 
956572ff6f6SMatthew Dillon 	if (ath_hal_eepromGet(ah, AR_EEP_MAXQCU, &val) == HAL_OK)
957572ff6f6SMatthew Dillon 		pCap->halTotalQueues = val;
958572ff6f6SMatthew Dillon 	else
959572ff6f6SMatthew Dillon 		pCap->halTotalQueues = HAL_NUM_TX_QUEUES;
960572ff6f6SMatthew Dillon 
961572ff6f6SMatthew Dillon 	if (ath_hal_eepromGet(ah, AR_EEP_KCENTRIES, &val) == HAL_OK)
962572ff6f6SMatthew Dillon 		pCap->halKeyCacheSize = val;
963572ff6f6SMatthew Dillon 	else
964572ff6f6SMatthew Dillon 		pCap->halKeyCacheSize = AR5416_KEYTABLE_SIZE;
965572ff6f6SMatthew Dillon 
966572ff6f6SMatthew Dillon 	/* XXX Which chips? */
967572ff6f6SMatthew Dillon 	pCap->halChanHalfRate = AH_TRUE;
968572ff6f6SMatthew Dillon 	pCap->halChanQuarterRate = AH_TRUE;
969572ff6f6SMatthew Dillon 
970572ff6f6SMatthew Dillon 	pCap->halTstampPrecision = 32;
971572ff6f6SMatthew Dillon 	pCap->halHwPhyCounterSupport = AH_TRUE;
972572ff6f6SMatthew Dillon 	pCap->halIntrMask = HAL_INT_COMMON
973572ff6f6SMatthew Dillon 			| HAL_INT_RX
974572ff6f6SMatthew Dillon 			| HAL_INT_TX
975572ff6f6SMatthew Dillon 			| HAL_INT_FATAL
976572ff6f6SMatthew Dillon 			| HAL_INT_BNR
977572ff6f6SMatthew Dillon 			| HAL_INT_BMISC
978572ff6f6SMatthew Dillon 			| HAL_INT_DTIMSYNC
979572ff6f6SMatthew Dillon 			| HAL_INT_TSFOOR
980572ff6f6SMatthew Dillon 			| HAL_INT_CST
981572ff6f6SMatthew Dillon 			| HAL_INT_GTT
982572ff6f6SMatthew Dillon 			;
983572ff6f6SMatthew Dillon 
984572ff6f6SMatthew Dillon 	pCap->halFastCCSupport = AH_TRUE;
985572ff6f6SMatthew Dillon 	pCap->halNumGpioPins = 14;
986572ff6f6SMatthew Dillon 	pCap->halWowSupport = AH_FALSE;
987572ff6f6SMatthew Dillon 	pCap->halWowMatchPatternExact = AH_FALSE;
988572ff6f6SMatthew Dillon 	pCap->halBtCoexSupport = AH_FALSE;	/* XXX need support */
989572ff6f6SMatthew Dillon 	pCap->halAutoSleepSupport = AH_FALSE;
990572ff6f6SMatthew Dillon 	pCap->hal4kbSplitTransSupport = AH_TRUE;
991572ff6f6SMatthew Dillon 	/* Disable this so Block-ACK works correctly */
992572ff6f6SMatthew Dillon 	pCap->halHasRxSelfLinkedTail = AH_FALSE;
993572ff6f6SMatthew Dillon #if 0	/* XXX not yet */
994572ff6f6SMatthew Dillon 	pCap->halNumAntCfg2GHz = ar5416GetNumAntConfig(ahp, HAL_FREQ_BAND_2GHZ);
995572ff6f6SMatthew Dillon 	pCap->halNumAntCfg5GHz = ar5416GetNumAntConfig(ahp, HAL_FREQ_BAND_5GHZ);
996572ff6f6SMatthew Dillon #endif
997572ff6f6SMatthew Dillon 	pCap->halHTSupport = AH_TRUE;
998572ff6f6SMatthew Dillon 	pCap->halTxChainMask = ath_hal_eepromGet(ah, AR_EEP_TXMASK, AH_NULL);
999572ff6f6SMatthew Dillon 	/* XXX CB71 uses GPIO 0 to indicate 3 rx chains */
1000572ff6f6SMatthew Dillon 	pCap->halRxChainMask = ath_hal_eepromGet(ah, AR_EEP_RXMASK, AH_NULL);
1001572ff6f6SMatthew Dillon 	/* AR5416 may have 3 antennas but is a 2x2 stream device */
1002572ff6f6SMatthew Dillon 	pCap->halTxStreams = 2;
1003572ff6f6SMatthew Dillon 	pCap->halRxStreams = 2;
1004572ff6f6SMatthew Dillon 
1005572ff6f6SMatthew Dillon 	/*
1006572ff6f6SMatthew Dillon 	 * If the TX or RX chainmask has less than 2 chains active,
1007572ff6f6SMatthew Dillon 	 * mark it as a 1-stream device for the relevant stream.
1008572ff6f6SMatthew Dillon 	 */
1009572ff6f6SMatthew Dillon 	if (owl_get_ntxchains(pCap->halTxChainMask) == 1)
1010572ff6f6SMatthew Dillon 		pCap->halTxStreams = 1;
1011572ff6f6SMatthew Dillon 	/* XXX Eww */
1012572ff6f6SMatthew Dillon 	if (owl_get_ntxchains(pCap->halRxChainMask) == 1)
1013572ff6f6SMatthew Dillon 		pCap->halRxStreams = 1;
1014572ff6f6SMatthew Dillon 	pCap->halRtsAggrLimit = 8*1024;		/* Owl 2.0 limit */
1015572ff6f6SMatthew Dillon 	pCap->halMbssidAggrSupport = AH_FALSE;	/* Broken on Owl */
1016572ff6f6SMatthew Dillon 	pCap->halForcePpmSupport = AH_TRUE;
1017572ff6f6SMatthew Dillon 	pCap->halEnhancedPmSupport = AH_TRUE;
1018572ff6f6SMatthew Dillon 	pCap->halBssidMatchSupport = AH_TRUE;
1019572ff6f6SMatthew Dillon 	pCap->halGTTSupport = AH_TRUE;
1020572ff6f6SMatthew Dillon 	pCap->halCSTSupport = AH_TRUE;
1021572ff6f6SMatthew Dillon 	pCap->halEnhancedDfsSupport = AH_FALSE;
1022572ff6f6SMatthew Dillon 	/* Hardware supports 32 bit TSF values in the RX descriptor */
1023572ff6f6SMatthew Dillon 	pCap->halHasLongRxDescTsf = AH_TRUE;
1024572ff6f6SMatthew Dillon 	/*
1025572ff6f6SMatthew Dillon 	 * BB Read WAR: this is only for AR5008/AR9001 NICs
1026572ff6f6SMatthew Dillon 	 * It is also set individually in the AR91xx attach functions.
1027572ff6f6SMatthew Dillon 	 */
1028572ff6f6SMatthew Dillon 	if (AR_SREV_OWL(ah))
1029572ff6f6SMatthew Dillon 		pCap->halHasBBReadWar = AH_TRUE;
1030572ff6f6SMatthew Dillon 
1031572ff6f6SMatthew Dillon 	if (ath_hal_eepromGetFlag(ah, AR_EEP_RFKILL) &&
1032572ff6f6SMatthew Dillon 	    ath_hal_eepromGet(ah, AR_EEP_RFSILENT, &ahpriv->ah_rfsilent) == HAL_OK) {
1033572ff6f6SMatthew Dillon 		/* NB: enabled by default */
1034572ff6f6SMatthew Dillon 		ahpriv->ah_rfkillEnabled = AH_TRUE;
1035572ff6f6SMatthew Dillon 		pCap->halRfSilentSupport = AH_TRUE;
1036572ff6f6SMatthew Dillon 	}
1037572ff6f6SMatthew Dillon 
1038572ff6f6SMatthew Dillon 	/*
1039572ff6f6SMatthew Dillon 	 * The MAC will mark frames as RXed if there's a descriptor
1040572ff6f6SMatthew Dillon 	 * to write them to. So if it hits a self-linked final descriptor,
1041572ff6f6SMatthew Dillon 	 * it'll keep ACKing frames even though they're being silently
1042572ff6f6SMatthew Dillon 	 * dropped. Thus, this particular feature of the driver can't
1043572ff6f6SMatthew Dillon 	 * be used for 802.11n devices.
1044572ff6f6SMatthew Dillon 	 */
1045572ff6f6SMatthew Dillon 	ahpriv->ah_rxornIsFatal = AH_FALSE;
1046572ff6f6SMatthew Dillon 
1047572ff6f6SMatthew Dillon 	/*
1048572ff6f6SMatthew Dillon 	 * If it's a PCI NIC, ask the HAL OS layer to serialise
1049572ff6f6SMatthew Dillon 	 * register access, or SMP machines may cause the hardware
1050572ff6f6SMatthew Dillon 	 * to hang. This is applicable to AR5416 and AR9220; I'm not
1051572ff6f6SMatthew Dillon 	 * sure about AR9160 or AR9227.
1052572ff6f6SMatthew Dillon 	 */
1053572ff6f6SMatthew Dillon 	if (! AH_PRIVATE(ah)->ah_ispcie)
1054572ff6f6SMatthew Dillon 		pCap->halSerialiseRegWar = 1;
1055572ff6f6SMatthew Dillon 
1056d98a0bcfSMatthew Dillon 	/*
1057d98a0bcfSMatthew Dillon 	 * AR5416 and later NICs support MYBEACON filtering.
1058d98a0bcfSMatthew Dillon 	 */
1059d98a0bcfSMatthew Dillon 	pCap->halRxDoMyBeacon = AH_TRUE;
1060d98a0bcfSMatthew Dillon 
1061572ff6f6SMatthew Dillon 	return AH_TRUE;
1062572ff6f6SMatthew Dillon }
1063572ff6f6SMatthew Dillon 
1064572ff6f6SMatthew Dillon static const char*
ar5416Probe(uint16_t vendorid,uint16_t devid)1065572ff6f6SMatthew Dillon ar5416Probe(uint16_t vendorid, uint16_t devid)
1066572ff6f6SMatthew Dillon {
1067572ff6f6SMatthew Dillon 	if (vendorid == ATHEROS_VENDOR_ID) {
1068572ff6f6SMatthew Dillon 		if (devid == AR5416_DEVID_PCI)
1069572ff6f6SMatthew Dillon 			return "Atheros 5416";
1070572ff6f6SMatthew Dillon 		if (devid == AR5416_DEVID_PCIE)
1071572ff6f6SMatthew Dillon 			return "Atheros 5418";
1072572ff6f6SMatthew Dillon 	}
1073572ff6f6SMatthew Dillon 	return AH_NULL;
1074572ff6f6SMatthew Dillon }
1075572ff6f6SMatthew Dillon AH_CHIP(AR5416, ar5416Probe, ar5416Attach);
1076