xref: /titanic_52/usr/src/uts/common/io/arn/arn_hw.c (revision c0c934808d1b7d058148814255f32064a0e09555)
1dd1de374Slin wang - Sun Microsystems - Beijing China /*
2*c0c93480Slin wang - Sun Microsystems - Beijing China  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
3dd1de374Slin wang - Sun Microsystems - Beijing China  * Use is subject to license terms.
4dd1de374Slin wang - Sun Microsystems - Beijing China  */
5dd1de374Slin wang - Sun Microsystems - Beijing China 
6dd1de374Slin wang - Sun Microsystems - Beijing China /*
7dd1de374Slin wang - Sun Microsystems - Beijing China  * Copyright (c) 2008 Atheros Communications Inc.
8dd1de374Slin wang - Sun Microsystems - Beijing China  *
9dd1de374Slin wang - Sun Microsystems - Beijing China  * Permission to use, copy, modify, and/or distribute this software for any
10dd1de374Slin wang - Sun Microsystems - Beijing China  * purpose with or without fee is hereby granted, provided that the above
11dd1de374Slin wang - Sun Microsystems - Beijing China  * copyright notice and this permission notice appear in all copies.
12dd1de374Slin wang - Sun Microsystems - Beijing China  *
13dd1de374Slin wang - Sun Microsystems - Beijing China  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14dd1de374Slin wang - Sun Microsystems - Beijing China  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15dd1de374Slin wang - Sun Microsystems - Beijing China  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16dd1de374Slin wang - Sun Microsystems - Beijing China  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17dd1de374Slin wang - Sun Microsystems - Beijing China  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18dd1de374Slin wang - Sun Microsystems - Beijing China  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19dd1de374Slin wang - Sun Microsystems - Beijing China  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20dd1de374Slin wang - Sun Microsystems - Beijing China  */
21dd1de374Slin wang - Sun Microsystems - Beijing China 
22dd1de374Slin wang - Sun Microsystems - Beijing China #include <sys/param.h>
23dd1de374Slin wang - Sun Microsystems - Beijing China #include <sys/types.h>
24dd1de374Slin wang - Sun Microsystems - Beijing China #include <sys/cmn_err.h>
25dd1de374Slin wang - Sun Microsystems - Beijing China #include <sys/kmem.h>
26dd1de374Slin wang - Sun Microsystems - Beijing China #include <sys/ddi.h>
27dd1de374Slin wang - Sun Microsystems - Beijing China #include <sys/sunddi.h>
28dd1de374Slin wang - Sun Microsystems - Beijing China #include <sys/varargs.h>
29dd1de374Slin wang - Sun Microsystems - Beijing China 
30dd1de374Slin wang - Sun Microsystems - Beijing China #include "arn_ath9k.h"
31dd1de374Slin wang - Sun Microsystems - Beijing China #include "arn_core.h"
32dd1de374Slin wang - Sun Microsystems - Beijing China #include "arn_hw.h"
33dd1de374Slin wang - Sun Microsystems - Beijing China #include "arn_reg.h"
34dd1de374Slin wang - Sun Microsystems - Beijing China #include "arn_phy.h"
35dd1de374Slin wang - Sun Microsystems - Beijing China #include "arn_initvals.h"
36dd1de374Slin wang - Sun Microsystems - Beijing China 
37dd1de374Slin wang - Sun Microsystems - Beijing China static const uint8_t CLOCK_RATE[] = { 40, 80, 22, 44, 88, 40 };
38dd1de374Slin wang - Sun Microsystems - Beijing China 
39dd1de374Slin wang - Sun Microsystems - Beijing China extern struct hal_percal_data iq_cal_multi_sample;
40dd1de374Slin wang - Sun Microsystems - Beijing China extern struct hal_percal_data iq_cal_single_sample;
41dd1de374Slin wang - Sun Microsystems - Beijing China extern struct hal_percal_data adc_gain_cal_multi_sample;
42dd1de374Slin wang - Sun Microsystems - Beijing China extern struct hal_percal_data adc_gain_cal_single_sample;
43dd1de374Slin wang - Sun Microsystems - Beijing China extern struct hal_percal_data adc_dc_cal_multi_sample;
44dd1de374Slin wang - Sun Microsystems - Beijing China extern struct hal_percal_data adc_dc_cal_single_sample;
45dd1de374Slin wang - Sun Microsystems - Beijing China extern struct hal_percal_data adc_init_dc_cal;
46dd1de374Slin wang - Sun Microsystems - Beijing China 
47dd1de374Slin wang - Sun Microsystems - Beijing China static boolean_t ath9k_hw_set_reset_reg(struct ath_hal *ah, uint32_t type);
48dd1de374Slin wang - Sun Microsystems - Beijing China static void ath9k_hw_set_regs(struct ath_hal *ah, struct ath9k_channel *chan,
49dd1de374Slin wang - Sun Microsystems - Beijing China     enum ath9k_ht_macmode macmode);
50dd1de374Slin wang - Sun Microsystems - Beijing China static uint32_t ath9k_hw_ini_fixup(struct ath_hal *ah,
51dd1de374Slin wang - Sun Microsystems - Beijing China     struct ar5416_eeprom_def *pEepData,
52dd1de374Slin wang - Sun Microsystems - Beijing China     uint32_t reg, uint32_t value);
53dd1de374Slin wang - Sun Microsystems - Beijing China static void ath9k_hw_9280_spur_mitigate(struct ath_hal *ah,
54dd1de374Slin wang - Sun Microsystems - Beijing China     struct ath9k_channel *chan);
55dd1de374Slin wang - Sun Microsystems - Beijing China static void ath9k_hw_spur_mitigate(struct ath_hal *ah,
56dd1de374Slin wang - Sun Microsystems - Beijing China     struct ath9k_channel *chan);
57dd1de374Slin wang - Sun Microsystems - Beijing China 
58dd1de374Slin wang - Sun Microsystems - Beijing China /* Helper Functions */
59dd1de374Slin wang - Sun Microsystems - Beijing China 
60dd1de374Slin wang - Sun Microsystems - Beijing China static uint32_t
61dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_mac_usec(struct ath_hal *ah, uint32_t clks)
62dd1de374Slin wang - Sun Microsystems - Beijing China {
63dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ah->ah_curchan != NULL)
64dd1de374Slin wang - Sun Microsystems - Beijing China 		return (clks /
65dd1de374Slin wang - Sun Microsystems - Beijing China 		    CLOCK_RATE[ath9k_hw_chan2wmode(ah, ah->ah_curchan)]);
66dd1de374Slin wang - Sun Microsystems - Beijing China 	else
67dd1de374Slin wang - Sun Microsystems - Beijing China 		return (clks / CLOCK_RATE[ATH9K_MODE_11B]);
68dd1de374Slin wang - Sun Microsystems - Beijing China }
69dd1de374Slin wang - Sun Microsystems - Beijing China 
70dd1de374Slin wang - Sun Microsystems - Beijing China static uint32_t
71dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_mac_to_usec(struct ath_hal *ah, uint32_t clks)
72dd1de374Slin wang - Sun Microsystems - Beijing China {
73dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath9k_channel *chan = ah->ah_curchan;
74dd1de374Slin wang - Sun Microsystems - Beijing China 
75dd1de374Slin wang - Sun Microsystems - Beijing China 	if (chan && IS_CHAN_HT40(chan))
76dd1de374Slin wang - Sun Microsystems - Beijing China 		return (ath9k_hw_mac_usec(ah, clks) / 2);
77dd1de374Slin wang - Sun Microsystems - Beijing China 	else
78dd1de374Slin wang - Sun Microsystems - Beijing China 		return (ath9k_hw_mac_usec(ah, clks));
79dd1de374Slin wang - Sun Microsystems - Beijing China }
80dd1de374Slin wang - Sun Microsystems - Beijing China 
81dd1de374Slin wang - Sun Microsystems - Beijing China static uint32_t
82dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_mac_clks(struct ath_hal *ah, uint32_t usecs)
83dd1de374Slin wang - Sun Microsystems - Beijing China {
84dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ah->ah_curchan != NULL)
85dd1de374Slin wang - Sun Microsystems - Beijing China 		return (usecs * CLOCK_RATE[ath9k_hw_chan2wmode(ah,
86dd1de374Slin wang - Sun Microsystems - Beijing China 		    ah->ah_curchan)]);
87dd1de374Slin wang - Sun Microsystems - Beijing China 	else
88dd1de374Slin wang - Sun Microsystems - Beijing China 		return (usecs * CLOCK_RATE[ATH9K_MODE_11B]);
89dd1de374Slin wang - Sun Microsystems - Beijing China }
90dd1de374Slin wang - Sun Microsystems - Beijing China 
91dd1de374Slin wang - Sun Microsystems - Beijing China static uint32_t
92dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_mac_to_clks(struct ath_hal *ah, uint32_t usecs)
93dd1de374Slin wang - Sun Microsystems - Beijing China {
94dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath9k_channel *chan = ah->ah_curchan;
95dd1de374Slin wang - Sun Microsystems - Beijing China 
96dd1de374Slin wang - Sun Microsystems - Beijing China 	if (chan && IS_CHAN_HT40(chan))
97dd1de374Slin wang - Sun Microsystems - Beijing China 		return (ath9k_hw_mac_clks(ah, usecs) * 2);
98dd1de374Slin wang - Sun Microsystems - Beijing China 	else
99dd1de374Slin wang - Sun Microsystems - Beijing China 		return (ath9k_hw_mac_clks(ah, usecs));
100dd1de374Slin wang - Sun Microsystems - Beijing China }
101dd1de374Slin wang - Sun Microsystems - Beijing China 
102dd1de374Slin wang - Sun Microsystems - Beijing China /* ARGSUSED */
103dd1de374Slin wang - Sun Microsystems - Beijing China enum wireless_mode
104dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_chan2wmode(struct ath_hal *ah, const struct ath9k_channel *chan)
105dd1de374Slin wang - Sun Microsystems - Beijing China {
106dd1de374Slin wang - Sun Microsystems - Beijing China 	if (IS_CHAN_B(chan))
107dd1de374Slin wang - Sun Microsystems - Beijing China 		return (ATH9K_MODE_11B);
108dd1de374Slin wang - Sun Microsystems - Beijing China 	if (IS_CHAN_G(chan))
109dd1de374Slin wang - Sun Microsystems - Beijing China 		return (ATH9K_MODE_11G);
110dd1de374Slin wang - Sun Microsystems - Beijing China 
111dd1de374Slin wang - Sun Microsystems - Beijing China 	return (ATH9K_MODE_11A);
112dd1de374Slin wang - Sun Microsystems - Beijing China }
113dd1de374Slin wang - Sun Microsystems - Beijing China 
114dd1de374Slin wang - Sun Microsystems - Beijing China boolean_t
115dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_wait(struct ath_hal *ah, uint32_t reg, uint32_t mask, uint32_t val)
116dd1de374Slin wang - Sun Microsystems - Beijing China {
117dd1de374Slin wang - Sun Microsystems - Beijing China 	int i;
118dd1de374Slin wang - Sun Microsystems - Beijing China 
119dd1de374Slin wang - Sun Microsystems - Beijing China 	for (i = 0; i < (AH_TIMEOUT / AH_TIME_QUANTUM); i++) {
120dd1de374Slin wang - Sun Microsystems - Beijing China 		if ((REG_READ(ah, reg) & mask) == val)
121dd1de374Slin wang - Sun Microsystems - Beijing China 			return (B_TRUE);
122dd1de374Slin wang - Sun Microsystems - Beijing China 
123dd1de374Slin wang - Sun Microsystems - Beijing China 		drv_usecwait(AH_TIME_QUANTUM);
124dd1de374Slin wang - Sun Microsystems - Beijing China 	}
125dd1de374Slin wang - Sun Microsystems - Beijing China 	ARN_DBG((ARN_DBG_HW, "arn: ath9k_hw_wait(): "
126dd1de374Slin wang - Sun Microsystems - Beijing China 	    "timeout on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
127dd1de374Slin wang - Sun Microsystems - Beijing China 	    reg, REG_READ(ah, reg), mask, val));
128dd1de374Slin wang - Sun Microsystems - Beijing China 
129dd1de374Slin wang - Sun Microsystems - Beijing China 	return (B_FALSE);
130dd1de374Slin wang - Sun Microsystems - Beijing China }
131dd1de374Slin wang - Sun Microsystems - Beijing China 
132dd1de374Slin wang - Sun Microsystems - Beijing China uint32_t
133dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_reverse_bits(uint32_t val, uint32_t n)
134dd1de374Slin wang - Sun Microsystems - Beijing China {
135dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t retval;
136dd1de374Slin wang - Sun Microsystems - Beijing China 	int i;
137dd1de374Slin wang - Sun Microsystems - Beijing China 
138dd1de374Slin wang - Sun Microsystems - Beijing China 	for (i = 0, retval = 0; i < n; i++) {
139dd1de374Slin wang - Sun Microsystems - Beijing China 		retval = (retval << 1) | (val & 1);
140dd1de374Slin wang - Sun Microsystems - Beijing China 		val >>= 1;
141dd1de374Slin wang - Sun Microsystems - Beijing China 	}
142dd1de374Slin wang - Sun Microsystems - Beijing China 	return (retval);
143dd1de374Slin wang - Sun Microsystems - Beijing China }
144dd1de374Slin wang - Sun Microsystems - Beijing China 
145dd1de374Slin wang - Sun Microsystems - Beijing China boolean_t
146dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_get_channel_edges(struct ath_hal *ah,
147dd1de374Slin wang - Sun Microsystems - Beijing China     uint16_t flags, uint16_t *low, uint16_t *high)
148dd1de374Slin wang - Sun Microsystems - Beijing China {
149dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
150dd1de374Slin wang - Sun Microsystems - Beijing China 
151dd1de374Slin wang - Sun Microsystems - Beijing China 	if (flags & CHANNEL_5GHZ) {
152dd1de374Slin wang - Sun Microsystems - Beijing China 		*low = pCap->low_5ghz_chan;
153dd1de374Slin wang - Sun Microsystems - Beijing China 		*high = pCap->high_5ghz_chan;
154dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_TRUE);
155dd1de374Slin wang - Sun Microsystems - Beijing China 	}
156dd1de374Slin wang - Sun Microsystems - Beijing China 	if ((flags & CHANNEL_2GHZ)) {
157dd1de374Slin wang - Sun Microsystems - Beijing China 		*low = pCap->low_2ghz_chan;
158dd1de374Slin wang - Sun Microsystems - Beijing China 		*high = pCap->high_2ghz_chan;
159dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_TRUE);
160dd1de374Slin wang - Sun Microsystems - Beijing China 	}
161dd1de374Slin wang - Sun Microsystems - Beijing China 	return (B_FALSE);
162dd1de374Slin wang - Sun Microsystems - Beijing China }
163dd1de374Slin wang - Sun Microsystems - Beijing China 
164dd1de374Slin wang - Sun Microsystems - Beijing China uint16_t
165dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_computetxtime(struct ath_hal *ah,
166dd1de374Slin wang - Sun Microsystems - Beijing China     struct ath_rate_table *rates,
167dd1de374Slin wang - Sun Microsystems - Beijing China     uint32_t frameLen, uint16_t rateix,
168dd1de374Slin wang - Sun Microsystems - Beijing China     boolean_t shortPreamble)
169dd1de374Slin wang - Sun Microsystems - Beijing China {
170dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
171dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t kbps;
172dd1de374Slin wang - Sun Microsystems - Beijing China 
173dd1de374Slin wang - Sun Microsystems - Beijing China 	kbps = rates->info[rateix].ratekbps;
174dd1de374Slin wang - Sun Microsystems - Beijing China 
175dd1de374Slin wang - Sun Microsystems - Beijing China 	if (kbps == 0)
176dd1de374Slin wang - Sun Microsystems - Beijing China 		return (0);
177dd1de374Slin wang - Sun Microsystems - Beijing China 
178dd1de374Slin wang - Sun Microsystems - Beijing China 	switch (rates->info[rateix].phy) {
179dd1de374Slin wang - Sun Microsystems - Beijing China 	case WLAN_RC_PHY_CCK:
180dd1de374Slin wang - Sun Microsystems - Beijing China 		phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
181dd1de374Slin wang - Sun Microsystems - Beijing China 		if (shortPreamble && rates->info[rateix].short_preamble)
182dd1de374Slin wang - Sun Microsystems - Beijing China 			phyTime >>= 1;
183dd1de374Slin wang - Sun Microsystems - Beijing China 		numBits = frameLen << 3;
184dd1de374Slin wang - Sun Microsystems - Beijing China 		txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
185dd1de374Slin wang - Sun Microsystems - Beijing China 		break;
186dd1de374Slin wang - Sun Microsystems - Beijing China 	case WLAN_RC_PHY_OFDM:
187dd1de374Slin wang - Sun Microsystems - Beijing China 		if (ah->ah_curchan && IS_CHAN_QUARTER_RATE(ah->ah_curchan)) {
188dd1de374Slin wang - Sun Microsystems - Beijing China 			bitsPerSymbol =
189dd1de374Slin wang - Sun Microsystems - Beijing China 			    (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
190dd1de374Slin wang - Sun Microsystems - Beijing China 			numBits = OFDM_PLCP_BITS + (frameLen << 3);
191dd1de374Slin wang - Sun Microsystems - Beijing China 			numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
192dd1de374Slin wang - Sun Microsystems - Beijing China 			txTime = OFDM_SIFS_TIME_QUARTER +
193dd1de374Slin wang - Sun Microsystems - Beijing China 			    OFDM_PREAMBLE_TIME_QUARTER +
194dd1de374Slin wang - Sun Microsystems - Beijing China 			    (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
195dd1de374Slin wang - Sun Microsystems - Beijing China 		} else if (ah->ah_curchan &&
196dd1de374Slin wang - Sun Microsystems - Beijing China 		    IS_CHAN_HALF_RATE(ah->ah_curchan)) {
197dd1de374Slin wang - Sun Microsystems - Beijing China 			bitsPerSymbol =	(kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
198dd1de374Slin wang - Sun Microsystems - Beijing China 			numBits = OFDM_PLCP_BITS + (frameLen << 3);
199dd1de374Slin wang - Sun Microsystems - Beijing China 			numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
200dd1de374Slin wang - Sun Microsystems - Beijing China 			txTime = OFDM_SIFS_TIME_HALF +
201dd1de374Slin wang - Sun Microsystems - Beijing China 			    OFDM_PREAMBLE_TIME_HALF +
202dd1de374Slin wang - Sun Microsystems - Beijing China 			    (numSymbols * OFDM_SYMBOL_TIME_HALF);
203dd1de374Slin wang - Sun Microsystems - Beijing China 		} else {
204dd1de374Slin wang - Sun Microsystems - Beijing China 			bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
205dd1de374Slin wang - Sun Microsystems - Beijing China 			numBits = OFDM_PLCP_BITS + (frameLen << 3);
206dd1de374Slin wang - Sun Microsystems - Beijing China 			numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
207dd1de374Slin wang - Sun Microsystems - Beijing China 			txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME +
208dd1de374Slin wang - Sun Microsystems - Beijing China 			    (numSymbols * OFDM_SYMBOL_TIME);
209dd1de374Slin wang - Sun Microsystems - Beijing China 		}
210dd1de374Slin wang - Sun Microsystems - Beijing China 		break;
211dd1de374Slin wang - Sun Microsystems - Beijing China 	default:
212dd1de374Slin wang - Sun Microsystems - Beijing China 		arn_problem("arn: "
213dd1de374Slin wang - Sun Microsystems - Beijing China 		    "%s: unknown phy %u (rate ix %u)\n", __func__,
214dd1de374Slin wang - Sun Microsystems - Beijing China 		    rates->info[rateix].phy, rateix);
215dd1de374Slin wang - Sun Microsystems - Beijing China 		txTime = 0;
216dd1de374Slin wang - Sun Microsystems - Beijing China 		break;
217dd1de374Slin wang - Sun Microsystems - Beijing China 	}
218dd1de374Slin wang - Sun Microsystems - Beijing China 
219dd1de374Slin wang - Sun Microsystems - Beijing China 	return ((uint16_t)txTime);
220dd1de374Slin wang - Sun Microsystems - Beijing China }
221dd1de374Slin wang - Sun Microsystems - Beijing China 
222dd1de374Slin wang - Sun Microsystems - Beijing China uint32_t
223dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_mhz2ieee(struct ath_hal *ah, uint32_t freq, uint32_t flags)
224dd1de374Slin wang - Sun Microsystems - Beijing China {
225dd1de374Slin wang - Sun Microsystems - Beijing China 	if (flags & CHANNEL_2GHZ) {
226dd1de374Slin wang - Sun Microsystems - Beijing China 		if (freq == 2484)
227dd1de374Slin wang - Sun Microsystems - Beijing China 			return (14);
228dd1de374Slin wang - Sun Microsystems - Beijing China 		if (freq < 2484)
229dd1de374Slin wang - Sun Microsystems - Beijing China 			return ((freq - 2407) / 5);
230dd1de374Slin wang - Sun Microsystems - Beijing China 		else
231dd1de374Slin wang - Sun Microsystems - Beijing China 			return (15 + ((freq - 2512) / 20));
232dd1de374Slin wang - Sun Microsystems - Beijing China 	} else if (flags & CHANNEL_5GHZ) {
233dd1de374Slin wang - Sun Microsystems - Beijing China 		if (ath9k_regd_is_public_safety_sku(ah) &&
234dd1de374Slin wang - Sun Microsystems - Beijing China 		    IS_CHAN_IN_PUBLIC_SAFETY_BAND(freq)) {
235dd1de374Slin wang - Sun Microsystems - Beijing China 			return (((freq * 10) +
236dd1de374Slin wang - Sun Microsystems - Beijing China 			    (((freq % 5) == 2) ? 5 : 0) - 49400) / 5);
237dd1de374Slin wang - Sun Microsystems - Beijing China 		} else if ((flags & CHANNEL_A) && (freq <= 5000)) {
238dd1de374Slin wang - Sun Microsystems - Beijing China 			return ((freq - 4000) / 5);
239dd1de374Slin wang - Sun Microsystems - Beijing China 		} else {
240dd1de374Slin wang - Sun Microsystems - Beijing China 			return ((freq - 5000) / 5);
241dd1de374Slin wang - Sun Microsystems - Beijing China 		}
242dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
243dd1de374Slin wang - Sun Microsystems - Beijing China 		if (freq == 2484)
244dd1de374Slin wang - Sun Microsystems - Beijing China 			return (14);
245dd1de374Slin wang - Sun Microsystems - Beijing China 		if (freq < 2484)
246dd1de374Slin wang - Sun Microsystems - Beijing China 			return ((freq - 2407) / 5);
247dd1de374Slin wang - Sun Microsystems - Beijing China 		if (freq < 5000) {
248dd1de374Slin wang - Sun Microsystems - Beijing China 			if (ath9k_regd_is_public_safety_sku(ah) &&
249dd1de374Slin wang - Sun Microsystems - Beijing China 			    IS_CHAN_IN_PUBLIC_SAFETY_BAND(freq)) {
250dd1de374Slin wang - Sun Microsystems - Beijing China 				return (((freq * 10) +
251dd1de374Slin wang - Sun Microsystems - Beijing China 				    (((freq % 5) ==
252dd1de374Slin wang - Sun Microsystems - Beijing China 				    2) ? 5 : 0) - 49400) / 5);
253dd1de374Slin wang - Sun Microsystems - Beijing China 			} else if (freq > 4900) {
254dd1de374Slin wang - Sun Microsystems - Beijing China 				return ((freq - 4000) / 5);
255dd1de374Slin wang - Sun Microsystems - Beijing China 			} else {
256dd1de374Slin wang - Sun Microsystems - Beijing China 				return (15 + ((freq - 2512) / 20));
257dd1de374Slin wang - Sun Microsystems - Beijing China 			}
258dd1de374Slin wang - Sun Microsystems - Beijing China 		}
259dd1de374Slin wang - Sun Microsystems - Beijing China 		return ((freq - 5000) / 5);
260dd1de374Slin wang - Sun Microsystems - Beijing China 	}
261dd1de374Slin wang - Sun Microsystems - Beijing China }
262dd1de374Slin wang - Sun Microsystems - Beijing China 
263dd1de374Slin wang - Sun Microsystems - Beijing China void
264dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_get_channel_centers(struct ath_hal *ah,
265dd1de374Slin wang - Sun Microsystems - Beijing China     struct ath9k_channel *chan,
266dd1de374Slin wang - Sun Microsystems - Beijing China     struct chan_centers *centers)
267dd1de374Slin wang - Sun Microsystems - Beijing China {
268dd1de374Slin wang - Sun Microsystems - Beijing China 	int8_t extoff;
269dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
270dd1de374Slin wang - Sun Microsystems - Beijing China 
271dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!IS_CHAN_HT40(chan)) {
272dd1de374Slin wang - Sun Microsystems - Beijing China 		centers->ctl_center = centers->ext_center =
273dd1de374Slin wang - Sun Microsystems - Beijing China 		    centers->synth_center = chan->channel;
274dd1de374Slin wang - Sun Microsystems - Beijing China 		return;
275dd1de374Slin wang - Sun Microsystems - Beijing China 	}
276dd1de374Slin wang - Sun Microsystems - Beijing China 
277dd1de374Slin wang - Sun Microsystems - Beijing China 	if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
278dd1de374Slin wang - Sun Microsystems - Beijing China 	    (chan->chanmode == CHANNEL_G_HT40PLUS)) {
279dd1de374Slin wang - Sun Microsystems - Beijing China 		centers->synth_center =
280dd1de374Slin wang - Sun Microsystems - Beijing China 		    chan->channel + HT40_CHANNEL_CENTER_SHIFT;
281dd1de374Slin wang - Sun Microsystems - Beijing China 		extoff = 1;
282dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
283dd1de374Slin wang - Sun Microsystems - Beijing China 		centers->synth_center =
284dd1de374Slin wang - Sun Microsystems - Beijing China 		    chan->channel - HT40_CHANNEL_CENTER_SHIFT;
285dd1de374Slin wang - Sun Microsystems - Beijing China 		extoff = -1;
286dd1de374Slin wang - Sun Microsystems - Beijing China 	}
287dd1de374Slin wang - Sun Microsystems - Beijing China 
288dd1de374Slin wang - Sun Microsystems - Beijing China 	centers->ctl_center =
289dd1de374Slin wang - Sun Microsystems - Beijing China 	    centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
290dd1de374Slin wang - Sun Microsystems - Beijing China 	centers->ext_center =
291dd1de374Slin wang - Sun Microsystems - Beijing China 	    centers->synth_center + (extoff *
292dd1de374Slin wang - Sun Microsystems - Beijing China 	    ((ahp->ah_extprotspacing == ATH9K_HT_EXTPROTSPACING_20) ?
293dd1de374Slin wang - Sun Microsystems - Beijing China 	    HT40_CHANNEL_CENTER_SHIFT : 15));
294dd1de374Slin wang - Sun Microsystems - Beijing China 
295dd1de374Slin wang - Sun Microsystems - Beijing China }
296dd1de374Slin wang - Sun Microsystems - Beijing China 
297dd1de374Slin wang - Sun Microsystems - Beijing China /* Chip Revisions */
298dd1de374Slin wang - Sun Microsystems - Beijing China 
299dd1de374Slin wang - Sun Microsystems - Beijing China static void
300dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_read_revisions(struct ath_hal *ah)
301dd1de374Slin wang - Sun Microsystems - Beijing China {
302dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t val;
303dd1de374Slin wang - Sun Microsystems - Beijing China 
304dd1de374Slin wang - Sun Microsystems - Beijing China 	val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
305dd1de374Slin wang - Sun Microsystems - Beijing China 
306dd1de374Slin wang - Sun Microsystems - Beijing China 	if (val == 0xFF) {
307dd1de374Slin wang - Sun Microsystems - Beijing China 		val = REG_READ(ah, AR_SREV);
308dd1de374Slin wang - Sun Microsystems - Beijing China 		ah->ah_macVersion = (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
309dd1de374Slin wang - Sun Microsystems - Beijing China 		ah->ah_macRev = MS(val, AR_SREV_REVISION2);
310dd1de374Slin wang - Sun Microsystems - Beijing China 		ah->ah_isPciExpress = (val & AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
311dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
312dd1de374Slin wang - Sun Microsystems - Beijing China 		if (!AR_SREV_9100(ah))
313dd1de374Slin wang - Sun Microsystems - Beijing China 			ah->ah_macVersion = MS(val, AR_SREV_VERSION);
314dd1de374Slin wang - Sun Microsystems - Beijing China 
315dd1de374Slin wang - Sun Microsystems - Beijing China 		ah->ah_macRev = val & AR_SREV_REVISION;
316dd1de374Slin wang - Sun Microsystems - Beijing China 
317dd1de374Slin wang - Sun Microsystems - Beijing China 		if (ah->ah_macVersion == AR_SREV_VERSION_5416_PCIE)
318dd1de374Slin wang - Sun Microsystems - Beijing China 			ah->ah_isPciExpress = B_TRUE;
319dd1de374Slin wang - Sun Microsystems - Beijing China 	}
320dd1de374Slin wang - Sun Microsystems - Beijing China }
321dd1de374Slin wang - Sun Microsystems - Beijing China 
322dd1de374Slin wang - Sun Microsystems - Beijing China static int
323dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_get_radiorev(struct ath_hal *ah)
324dd1de374Slin wang - Sun Microsystems - Beijing China {
325dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t val;
326dd1de374Slin wang - Sun Microsystems - Beijing China 	int i;
327dd1de374Slin wang - Sun Microsystems - Beijing China 
328dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY(0x36), 0x00007058);
329dd1de374Slin wang - Sun Microsystems - Beijing China 
330dd1de374Slin wang - Sun Microsystems - Beijing China 	for (i = 0; i < 8; i++)
331dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PHY(0x20), 0x00010000);
332dd1de374Slin wang - Sun Microsystems - Beijing China 	val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff;
333dd1de374Slin wang - Sun Microsystems - Beijing China 	val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4);
334dd1de374Slin wang - Sun Microsystems - Beijing China 
335dd1de374Slin wang - Sun Microsystems - Beijing China 	return (ath9k_hw_reverse_bits(val, 8));
336dd1de374Slin wang - Sun Microsystems - Beijing China }
337dd1de374Slin wang - Sun Microsystems - Beijing China 
338dd1de374Slin wang - Sun Microsystems - Beijing China /* HW Attach, Detach, Init Routines */
339dd1de374Slin wang - Sun Microsystems - Beijing China 
340dd1de374Slin wang - Sun Microsystems - Beijing China static void
341dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_disablepcie(struct ath_hal *ah)
342dd1de374Slin wang - Sun Microsystems - Beijing China {
343dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!AR_SREV_9100(ah))
344dd1de374Slin wang - Sun Microsystems - Beijing China 		return;
345dd1de374Slin wang - Sun Microsystems - Beijing China 
346dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
347dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
348dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
349dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
350dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
351dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
352dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
353dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
354dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
355dd1de374Slin wang - Sun Microsystems - Beijing China 
356dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
357dd1de374Slin wang - Sun Microsystems - Beijing China }
358dd1de374Slin wang - Sun Microsystems - Beijing China 
359dd1de374Slin wang - Sun Microsystems - Beijing China static boolean_t
360dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_chip_test(struct ath_hal *ah)
361dd1de374Slin wang - Sun Microsystems - Beijing China {
362dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t regAddr[2] = { AR_STA_ID0, AR_PHY_BASE + (8 << 2) };
363dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t regHold[2];
364dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t patternData[4] = { 0x55555555, 0xaaaaaaaa,
365dd1de374Slin wang - Sun Microsystems - Beijing China 	    0x66666666, 0x99999999 };
366dd1de374Slin wang - Sun Microsystems - Beijing China 	int i, j;
367dd1de374Slin wang - Sun Microsystems - Beijing China 
368dd1de374Slin wang - Sun Microsystems - Beijing China 	for (i = 0; i < 2; i++) {
369dd1de374Slin wang - Sun Microsystems - Beijing China 		uint32_t addr = regAddr[i];
370dd1de374Slin wang - Sun Microsystems - Beijing China 		uint32_t wrData, rdData;
371dd1de374Slin wang - Sun Microsystems - Beijing China 
372dd1de374Slin wang - Sun Microsystems - Beijing China 		regHold[i] = REG_READ(ah, addr);
373dd1de374Slin wang - Sun Microsystems - Beijing China 		for (j = 0; j < 0x100; j++) {
374dd1de374Slin wang - Sun Microsystems - Beijing China 			wrData = (j << 16) | j;
375dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_WRITE(ah, addr, wrData);
376dd1de374Slin wang - Sun Microsystems - Beijing China 			rdData = REG_READ(ah, addr);
377dd1de374Slin wang - Sun Microsystems - Beijing China 			if (rdData != wrData) {
378dd1de374Slin wang - Sun Microsystems - Beijing China 				ARN_DBG((ARN_DBG_REG_IO,
379dd1de374Slin wang - Sun Microsystems - Beijing China 				    "arn: ath9k_hw_chip_test(): "
380dd1de374Slin wang - Sun Microsystems - Beijing China 				    "address test failed "
381dd1de374Slin wang - Sun Microsystems - Beijing China 				    "addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
382dd1de374Slin wang - Sun Microsystems - Beijing China 				    addr, wrData, rdData));
383dd1de374Slin wang - Sun Microsystems - Beijing China 
384dd1de374Slin wang - Sun Microsystems - Beijing China 				return (B_FALSE);
385dd1de374Slin wang - Sun Microsystems - Beijing China 			}
386dd1de374Slin wang - Sun Microsystems - Beijing China 		}
387dd1de374Slin wang - Sun Microsystems - Beijing China 		for (j = 0; j < 4; j++) {
388dd1de374Slin wang - Sun Microsystems - Beijing China 			wrData = patternData[j];
389dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_WRITE(ah, addr, wrData);
390dd1de374Slin wang - Sun Microsystems - Beijing China 			rdData = REG_READ(ah, addr);
391dd1de374Slin wang - Sun Microsystems - Beijing China 			if (wrData != rdData) {
392dd1de374Slin wang - Sun Microsystems - Beijing China 				ARN_DBG((ARN_DBG_REG_IO,
393dd1de374Slin wang - Sun Microsystems - Beijing China 				    "arn: ath9k_hw_chip_test(): "
394dd1de374Slin wang - Sun Microsystems - Beijing China 				    "address test failed "
395dd1de374Slin wang - Sun Microsystems - Beijing China 				    "addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
396dd1de374Slin wang - Sun Microsystems - Beijing China 				    addr, wrData, rdData));
397dd1de374Slin wang - Sun Microsystems - Beijing China 
398dd1de374Slin wang - Sun Microsystems - Beijing China 				return (B_FALSE);
399dd1de374Slin wang - Sun Microsystems - Beijing China 			}
400dd1de374Slin wang - Sun Microsystems - Beijing China 		}
401dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, regAddr[i], regHold[i]);
402dd1de374Slin wang - Sun Microsystems - Beijing China 	}
403dd1de374Slin wang - Sun Microsystems - Beijing China 	drv_usecwait(100);
404dd1de374Slin wang - Sun Microsystems - Beijing China 
405dd1de374Slin wang - Sun Microsystems - Beijing China 	return (B_TRUE);
406dd1de374Slin wang - Sun Microsystems - Beijing China }
407dd1de374Slin wang - Sun Microsystems - Beijing China 
408dd1de374Slin wang - Sun Microsystems - Beijing China static const char *
409dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_devname(uint16_t devid)
410dd1de374Slin wang - Sun Microsystems - Beijing China {
411dd1de374Slin wang - Sun Microsystems - Beijing China 	switch (devid) {
412dd1de374Slin wang - Sun Microsystems - Beijing China 	case AR5416_DEVID_PCI:
413dd1de374Slin wang - Sun Microsystems - Beijing China 		return ("Atheros 5416");
414dd1de374Slin wang - Sun Microsystems - Beijing China 	case AR5416_DEVID_PCIE:
415dd1de374Slin wang - Sun Microsystems - Beijing China 		return ("Atheros 5418");
416dd1de374Slin wang - Sun Microsystems - Beijing China 	case AR9160_DEVID_PCI:
417dd1de374Slin wang - Sun Microsystems - Beijing China 		return ("Atheros 9160");
418dd1de374Slin wang - Sun Microsystems - Beijing China 	case AR9280_DEVID_PCI:
419dd1de374Slin wang - Sun Microsystems - Beijing China 	case AR9280_DEVID_PCIE:
420dd1de374Slin wang - Sun Microsystems - Beijing China 		return ("Atheros 9280");
421dd1de374Slin wang - Sun Microsystems - Beijing China 	case AR9285_DEVID_PCIE:
422dd1de374Slin wang - Sun Microsystems - Beijing China 		return ("Atheros 9285");
423dd1de374Slin wang - Sun Microsystems - Beijing China 	}
424dd1de374Slin wang - Sun Microsystems - Beijing China 
425dd1de374Slin wang - Sun Microsystems - Beijing China 	return (NULL);
426dd1de374Slin wang - Sun Microsystems - Beijing China }
427dd1de374Slin wang - Sun Microsystems - Beijing China 
428dd1de374Slin wang - Sun Microsystems - Beijing China static void
429dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_set_defaults(struct ath_hal *ah)
430dd1de374Slin wang - Sun Microsystems - Beijing China {
431dd1de374Slin wang - Sun Microsystems - Beijing China 	int i;
432dd1de374Slin wang - Sun Microsystems - Beijing China 
433dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_config.dma_beacon_response_time = 2;
434dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_config.sw_beacon_response_time = 10;
435dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_config.additional_swba_backoff = 0;
436dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_config.ack_6mb = 0x0;
437dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_config.cwm_ignore_extcca = 0;
438dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_config.pcie_powersave_enable = 0;
439dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_config.pcie_l1skp_enable = 0;
440dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_config.pcie_clock_req = 0;
441dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_config.pcie_power_reset = 0x100;
442dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_config.pcie_restore = 0;
443dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_config.pcie_waen = 0;
444dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_config.analog_shiftreg = 1;
445dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_config.ht_enable = 1;
446dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_config.ofdm_trig_low = 200;
447dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_config.ofdm_trig_high = 500;
448dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_config.cck_trig_high = 200;
449dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_config.cck_trig_low = 100;
450dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_config.enable_ani = 1;
451dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_config.noise_immunity_level = 4;
452dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_config.ofdm_weaksignal_det = 1;
453dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_config.cck_weaksignal_thr = 0;
454dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_config.spur_immunity_level = 2;
455dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_config.firstep_level = 0;
456dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_config.rssi_thr_high = 40;
457dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_config.rssi_thr_low = 7;
458dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_config.diversity_control = 0;
459dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_config.antenna_switch_swap = 0;
460dd1de374Slin wang - Sun Microsystems - Beijing China 
461dd1de374Slin wang - Sun Microsystems - Beijing China 	for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
462dd1de374Slin wang - Sun Microsystems - Beijing China 		ah->ah_config.spurchans[i][0] = AR_NO_SPUR;
463dd1de374Slin wang - Sun Microsystems - Beijing China 		ah->ah_config.spurchans[i][1] = AR_NO_SPUR;
464dd1de374Slin wang - Sun Microsystems - Beijing China 	}
465dd1de374Slin wang - Sun Microsystems - Beijing China 
466dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_config.intr_mitigation = 1;
467dd1de374Slin wang - Sun Microsystems - Beijing China 
468dd1de374Slin wang - Sun Microsystems - Beijing China 	/*
469dd1de374Slin wang - Sun Microsystems - Beijing China 	 * We need this for PCI devices only (Cardbus, PCI, miniPCI)
470dd1de374Slin wang - Sun Microsystems - Beijing China 	 * _and_ if on non-uniprocessor systems (Multiprocessor/HT).
471dd1de374Slin wang - Sun Microsystems - Beijing China 	 * This means we use it for all AR5416 devices, and the few
472dd1de374Slin wang - Sun Microsystems - Beijing China 	 * minor PCI AR9280 devices out there.
473dd1de374Slin wang - Sun Microsystems - Beijing China 	 *
474dd1de374Slin wang - Sun Microsystems - Beijing China 	 * Serialization is required because these devices do not handle
475dd1de374Slin wang - Sun Microsystems - Beijing China 	 * well the case of two concurrent reads/writes due to the latency
476dd1de374Slin wang - Sun Microsystems - Beijing China 	 * involved. During one read/write another read/write can be issued
477dd1de374Slin wang - Sun Microsystems - Beijing China 	 * on another CPU while the previous read/write may still be working
478dd1de374Slin wang - Sun Microsystems - Beijing China 	 * on our hardware, if we hit this case the hardware poops in a loop.
479dd1de374Slin wang - Sun Microsystems - Beijing China 	 * We prevent this by serializing reads and writes.
480dd1de374Slin wang - Sun Microsystems - Beijing China 	 *
481dd1de374Slin wang - Sun Microsystems - Beijing China 	 * This issue is not present on PCI-Express devices or pre-AR5416
482dd1de374Slin wang - Sun Microsystems - Beijing China 	 * devices (legacy, 802.11abg).
483dd1de374Slin wang - Sun Microsystems - Beijing China 	 */
484dd1de374Slin wang - Sun Microsystems - Beijing China 
485dd1de374Slin wang - Sun Microsystems - Beijing China 	/* num_of_cpus */
486dd1de374Slin wang - Sun Microsystems - Beijing China }
487dd1de374Slin wang - Sun Microsystems - Beijing China 
488dd1de374Slin wang - Sun Microsystems - Beijing China static struct ath_hal_5416 *
489dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_newstate(uint16_t device_id, struct arn_softc *sc, caddr_t mem,
490dd1de374Slin wang - Sun Microsystems - Beijing China     int *status)
491dd1de374Slin wang - Sun Microsystems - Beijing China {
492dd1de374Slin wang - Sun Microsystems - Beijing China 	static const uint8_t defbssidmask[IEEE80211_ADDR_LEN] =
493dd1de374Slin wang - Sun Microsystems - Beijing China 	    { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
494dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp;
495dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal *ah;
496dd1de374Slin wang - Sun Microsystems - Beijing China 
497dd1de374Slin wang - Sun Microsystems - Beijing China 	ahp = (struct ath_hal_5416 *)
498dd1de374Slin wang - Sun Microsystems - Beijing China 	    kmem_zalloc(sizeof (struct ath_hal_5416), KM_SLEEP);
499dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ahp == NULL) {
500dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_ANY, "arn: ath9k_hw_newstate(): "
501dd1de374Slin wang - Sun Microsystems - Beijing China 		    "failed to alloc mem for ahp\n"));
502dd1de374Slin wang - Sun Microsystems - Beijing China 		*status = ENOMEM;
503dd1de374Slin wang - Sun Microsystems - Beijing China 		return (NULL);
504dd1de374Slin wang - Sun Microsystems - Beijing China 	}
505dd1de374Slin wang - Sun Microsystems - Beijing China 
506dd1de374Slin wang - Sun Microsystems - Beijing China 	ah = &ahp->ah;
507dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_sc = sc;
508dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_sh = mem;
509dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_magic = AR5416_MAGIC;
510dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_countryCode = CTRY_DEFAULT;
511dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_devid = device_id;
512dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_subvendorid = 0;
513dd1de374Slin wang - Sun Microsystems - Beijing China 
514dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_flags = 0;
515dd1de374Slin wang - Sun Microsystems - Beijing China 	if ((device_id == AR5416_AR9100_DEVID))
516dd1de374Slin wang - Sun Microsystems - Beijing China 		ah->ah_macVersion = AR_SREV_VERSION_9100;
517dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!AR_SREV_9100(ah))
518dd1de374Slin wang - Sun Microsystems - Beijing China 		ah->ah_flags = AH_USE_EEPROM;
519dd1de374Slin wang - Sun Microsystems - Beijing China 
520dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_powerLimit = MAX_RATE_POWER;
521dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_tpScale = ATH9K_TP_SCALE_MAX;
522dd1de374Slin wang - Sun Microsystems - Beijing China 	ahp->ah_atimWindow = 0;
523dd1de374Slin wang - Sun Microsystems - Beijing China 	ahp->ah_diversityControl = ah->ah_config.diversity_control;
524dd1de374Slin wang - Sun Microsystems - Beijing China 	ahp->ah_antennaSwitchSwap =
525dd1de374Slin wang - Sun Microsystems - Beijing China 	    ah->ah_config.antenna_switch_swap;
526dd1de374Slin wang - Sun Microsystems - Beijing China 	ahp->ah_staId1Defaults = AR_STA_ID1_CRPT_MIC_ENABLE;
527dd1de374Slin wang - Sun Microsystems - Beijing China 	ahp->ah_beaconInterval = 100;
528dd1de374Slin wang - Sun Microsystems - Beijing China 	ahp->ah_enable32kHzClock = DONT_USE_32KHZ;
529dd1de374Slin wang - Sun Microsystems - Beijing China 	ahp->ah_slottime = (uint32_t)-1;
530dd1de374Slin wang - Sun Microsystems - Beijing China 	ahp->ah_acktimeout = (uint32_t)-1;
531dd1de374Slin wang - Sun Microsystems - Beijing China 	ahp->ah_ctstimeout = (uint32_t)-1;
532dd1de374Slin wang - Sun Microsystems - Beijing China 	ahp->ah_globaltxtimeout = (uint32_t)-1;
533dd1de374Slin wang - Sun Microsystems - Beijing China 	(void) memcpy(&ahp->ah_bssidmask, defbssidmask, IEEE80211_ADDR_LEN);
534dd1de374Slin wang - Sun Microsystems - Beijing China 
535dd1de374Slin wang - Sun Microsystems - Beijing China 	ahp->ah_gBeaconRate = 0;
536dd1de374Slin wang - Sun Microsystems - Beijing China 
537dd1de374Slin wang - Sun Microsystems - Beijing China 	return (ahp);
538dd1de374Slin wang - Sun Microsystems - Beijing China }
539dd1de374Slin wang - Sun Microsystems - Beijing China 
540dd1de374Slin wang - Sun Microsystems - Beijing China static int
541dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_rfattach(struct ath_hal *ah)
542dd1de374Slin wang - Sun Microsystems - Beijing China {
543dd1de374Slin wang - Sun Microsystems - Beijing China 	boolean_t  rfStatus = B_FALSE;
544dd1de374Slin wang - Sun Microsystems - Beijing China 	int ecode = 0;
545dd1de374Slin wang - Sun Microsystems - Beijing China 
546dd1de374Slin wang - Sun Microsystems - Beijing China 	rfStatus = ath9k_hw_init_rf(ah, &ecode);
547dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!rfStatus) {
548dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_HW, "arn: ath9k_hw_rfattach(): "
549dd1de374Slin wang - Sun Microsystems - Beijing China 		    "RF setup failed, status %u\n", ecode));
550dd1de374Slin wang - Sun Microsystems - Beijing China 
551dd1de374Slin wang - Sun Microsystems - Beijing China 		return (ecode);
552dd1de374Slin wang - Sun Microsystems - Beijing China 	}
553dd1de374Slin wang - Sun Microsystems - Beijing China 
554dd1de374Slin wang - Sun Microsystems - Beijing China 	return (0);
555dd1de374Slin wang - Sun Microsystems - Beijing China }
556dd1de374Slin wang - Sun Microsystems - Beijing China 
557dd1de374Slin wang - Sun Microsystems - Beijing China static int
558dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_rf_claim(struct ath_hal *ah)
559dd1de374Slin wang - Sun Microsystems - Beijing China {
560dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t val;
561dd1de374Slin wang - Sun Microsystems - Beijing China 
562dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY(0), 0x00000007);
563dd1de374Slin wang - Sun Microsystems - Beijing China 
564dd1de374Slin wang - Sun Microsystems - Beijing China 	val = ath9k_hw_get_radiorev(ah);
565dd1de374Slin wang - Sun Microsystems - Beijing China 	switch (val & AR_RADIO_SREV_MAJOR) {
566dd1de374Slin wang - Sun Microsystems - Beijing China 	case 0:
567dd1de374Slin wang - Sun Microsystems - Beijing China 		val = AR_RAD5133_SREV_MAJOR;
568dd1de374Slin wang - Sun Microsystems - Beijing China 		break;
569dd1de374Slin wang - Sun Microsystems - Beijing China 	case AR_RAD5133_SREV_MAJOR:
570dd1de374Slin wang - Sun Microsystems - Beijing China 	case AR_RAD5122_SREV_MAJOR:
571dd1de374Slin wang - Sun Microsystems - Beijing China 	case AR_RAD2133_SREV_MAJOR:
572dd1de374Slin wang - Sun Microsystems - Beijing China 	case AR_RAD2122_SREV_MAJOR:
573dd1de374Slin wang - Sun Microsystems - Beijing China 		break;
574dd1de374Slin wang - Sun Microsystems - Beijing China 	default:
575dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_CHANNEL,
576dd1de374Slin wang - Sun Microsystems - Beijing China 		    "arn: ath9k_hw_rf_claim(): "
577dd1de374Slin wang - Sun Microsystems - Beijing China 		    "5G Radio Chip Rev 0x%02X "
578dd1de374Slin wang - Sun Microsystems - Beijing China 		    "is not supported by this driver\n",
579dd1de374Slin wang - Sun Microsystems - Beijing China 		    ah->ah_analog5GhzRev));
580dd1de374Slin wang - Sun Microsystems - Beijing China 
581dd1de374Slin wang - Sun Microsystems - Beijing China 		return (ENOTSUP);
582dd1de374Slin wang - Sun Microsystems - Beijing China 	}
583dd1de374Slin wang - Sun Microsystems - Beijing China 
584dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_analog5GhzRev = (uint16_t)val;
585dd1de374Slin wang - Sun Microsystems - Beijing China 
586dd1de374Slin wang - Sun Microsystems - Beijing China 	return (0);
587dd1de374Slin wang - Sun Microsystems - Beijing China }
588dd1de374Slin wang - Sun Microsystems - Beijing China 
589dd1de374Slin wang - Sun Microsystems - Beijing China static int
590dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_init_macaddr(struct ath_hal *ah)
591dd1de374Slin wang - Sun Microsystems - Beijing China {
592dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t sum;
593dd1de374Slin wang - Sun Microsystems - Beijing China 	int i;
594dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t eeval;
595dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
596dd1de374Slin wang - Sun Microsystems - Beijing China 
597dd1de374Slin wang - Sun Microsystems - Beijing China 	sum = 0;
598dd1de374Slin wang - Sun Microsystems - Beijing China 	for (i = 0; i < 3; i++) {
599dd1de374Slin wang - Sun Microsystems - Beijing China 		eeval = ath9k_hw_get_eeprom(ah, AR_EEPROM_MAC(i));
600dd1de374Slin wang - Sun Microsystems - Beijing China 		sum += eeval;
601dd1de374Slin wang - Sun Microsystems - Beijing China 		ahp->ah_macaddr[2 * i] = eeval >> 8;
602dd1de374Slin wang - Sun Microsystems - Beijing China 		ahp->ah_macaddr[2 * i + 1] = eeval & 0xff;
603dd1de374Slin wang - Sun Microsystems - Beijing China 	}
604dd1de374Slin wang - Sun Microsystems - Beijing China 	if (sum == 0 || sum == 0xffff * 3) {
605dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_EEPROM, "arn: ath9k_hw_init_macaddr(): "
606dd1de374Slin wang - Sun Microsystems - Beijing China 		    "mac address read failed: %pM\n",
607dd1de374Slin wang - Sun Microsystems - Beijing China 		    ahp->ah_macaddr));
608dd1de374Slin wang - Sun Microsystems - Beijing China 
609dd1de374Slin wang - Sun Microsystems - Beijing China 		return (EADDRNOTAVAIL);
610dd1de374Slin wang - Sun Microsystems - Beijing China 	}
611dd1de374Slin wang - Sun Microsystems - Beijing China 
612dd1de374Slin wang - Sun Microsystems - Beijing China 	return (0);
613dd1de374Slin wang - Sun Microsystems - Beijing China }
614dd1de374Slin wang - Sun Microsystems - Beijing China 
615dd1de374Slin wang - Sun Microsystems - Beijing China static void
616dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_init_rxgain_ini(struct ath_hal *ah)
617dd1de374Slin wang - Sun Microsystems - Beijing China {
618dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t rxgain_type;
619dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
620dd1de374Slin wang - Sun Microsystems - Beijing China 
621dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ath9k_hw_get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_17) {
622dd1de374Slin wang - Sun Microsystems - Beijing China 		rxgain_type = ath9k_hw_get_eeprom(ah, EEP_RXGAIN_TYPE);
623dd1de374Slin wang - Sun Microsystems - Beijing China 		if (rxgain_type == AR5416_EEP_RXGAIN_13DB_BACKOFF) {
624dd1de374Slin wang - Sun Microsystems - Beijing China 			INIT_INI_ARRAY(&ahp->ah_iniModesRxGain,
625dd1de374Slin wang - Sun Microsystems - Beijing China 			    ar9280Modes_backoff_13db_rxgain_9280_2,
626dd1de374Slin wang - Sun Microsystems - Beijing China 			    ARRAY_SIZE(ar9280Modes_backoff_13db_rxgain_9280_2),
627dd1de374Slin wang - Sun Microsystems - Beijing China 			    6);
628dd1de374Slin wang - Sun Microsystems - Beijing China 		} else if (rxgain_type == AR5416_EEP_RXGAIN_23DB_BACKOFF) {
629dd1de374Slin wang - Sun Microsystems - Beijing China 			INIT_INI_ARRAY(&ahp->ah_iniModesRxGain,
630dd1de374Slin wang - Sun Microsystems - Beijing China 			    ar9280Modes_backoff_23db_rxgain_9280_2,
631dd1de374Slin wang - Sun Microsystems - Beijing China 			    ARRAY_SIZE(ar9280Modes_backoff_23db_rxgain_9280_2),
632dd1de374Slin wang - Sun Microsystems - Beijing China 			    6);
633dd1de374Slin wang - Sun Microsystems - Beijing China 			} else {
634dd1de374Slin wang - Sun Microsystems - Beijing China 			INIT_INI_ARRAY(&ahp->ah_iniModesRxGain,
635dd1de374Slin wang - Sun Microsystems - Beijing China 			    ar9280Modes_original_rxgain_9280_2,
636dd1de374Slin wang - Sun Microsystems - Beijing China 			    ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
637dd1de374Slin wang - Sun Microsystems - Beijing China 		}
638dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
639dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniModesRxGain,
640dd1de374Slin wang - Sun Microsystems - Beijing China 		    ar9280Modes_original_rxgain_9280_2,
641dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
642dd1de374Slin wang - Sun Microsystems - Beijing China 	}
643dd1de374Slin wang - Sun Microsystems - Beijing China }
644dd1de374Slin wang - Sun Microsystems - Beijing China 
645dd1de374Slin wang - Sun Microsystems - Beijing China static void
646dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_init_txgain_ini(struct ath_hal *ah)
647dd1de374Slin wang - Sun Microsystems - Beijing China {
648dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t txgain_type;
649dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
650dd1de374Slin wang - Sun Microsystems - Beijing China 
651dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ath9k_hw_get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_19) {
652dd1de374Slin wang - Sun Microsystems - Beijing China 		txgain_type = ath9k_hw_get_eeprom(ah, EEP_TXGAIN_TYPE);
653dd1de374Slin wang - Sun Microsystems - Beijing China 
654dd1de374Slin wang - Sun Microsystems - Beijing China 		if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) {
655dd1de374Slin wang - Sun Microsystems - Beijing China 			INIT_INI_ARRAY(&ahp->ah_iniModesTxGain,
656dd1de374Slin wang - Sun Microsystems - Beijing China 			    ar9280Modes_high_power_tx_gain_9280_2,
657dd1de374Slin wang - Sun Microsystems - Beijing China 			    ARRAY_SIZE(ar9280Modes_high_power_tx_gain_9280_2),
658dd1de374Slin wang - Sun Microsystems - Beijing China 			    6);
659dd1de374Slin wang - Sun Microsystems - Beijing China 			} else {
660dd1de374Slin wang - Sun Microsystems - Beijing China 			INIT_INI_ARRAY(&ahp->ah_iniModesTxGain,
661dd1de374Slin wang - Sun Microsystems - Beijing China 			    ar9280Modes_original_tx_gain_9280_2,
662dd1de374Slin wang - Sun Microsystems - Beijing China 			    ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
663dd1de374Slin wang - Sun Microsystems - Beijing China 		}
664dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
665dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniModesTxGain,
666dd1de374Slin wang - Sun Microsystems - Beijing China 		    ar9280Modes_original_tx_gain_9280_2,
667dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
668dd1de374Slin wang - Sun Microsystems - Beijing China 	}
669dd1de374Slin wang - Sun Microsystems - Beijing China }
670dd1de374Slin wang - Sun Microsystems - Beijing China 
671dd1de374Slin wang - Sun Microsystems - Beijing China static int
672dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_post_attach(struct ath_hal *ah)
673dd1de374Slin wang - Sun Microsystems - Beijing China {
674dd1de374Slin wang - Sun Microsystems - Beijing China 	int ecode;
675dd1de374Slin wang - Sun Microsystems - Beijing China 
676dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!ath9k_hw_chip_test(ah)) {
677dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_REG_IO, "arn: ath9k_hw_post_attach(): "
678dd1de374Slin wang - Sun Microsystems - Beijing China 		    "hardware self-test failed\n"));
679dd1de374Slin wang - Sun Microsystems - Beijing China 
680dd1de374Slin wang - Sun Microsystems - Beijing China 	}
681dd1de374Slin wang - Sun Microsystems - Beijing China 
682dd1de374Slin wang - Sun Microsystems - Beijing China 	ecode = ath9k_hw_rf_claim(ah);
683dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ecode != 0)
684dd1de374Slin wang - Sun Microsystems - Beijing China 		return (ecode);
685dd1de374Slin wang - Sun Microsystems - Beijing China 
686dd1de374Slin wang - Sun Microsystems - Beijing China 	ecode = ath9k_hw_eeprom_attach(ah);
687dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ecode != 0)
688dd1de374Slin wang - Sun Microsystems - Beijing China 		return (ecode);
689dd1de374Slin wang - Sun Microsystems - Beijing China 	ecode = ath9k_hw_rfattach(ah);
690dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ecode != 0)
691dd1de374Slin wang - Sun Microsystems - Beijing China 		return (ecode);
692dd1de374Slin wang - Sun Microsystems - Beijing China 
693dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!AR_SREV_9100(ah)) {
694dd1de374Slin wang - Sun Microsystems - Beijing China 		ath9k_hw_ani_setup(ah);
695dd1de374Slin wang - Sun Microsystems - Beijing China 		ath9k_hw_ani_attach(ah);
696dd1de374Slin wang - Sun Microsystems - Beijing China 	}
697dd1de374Slin wang - Sun Microsystems - Beijing China 
698dd1de374Slin wang - Sun Microsystems - Beijing China 	return (0);
699dd1de374Slin wang - Sun Microsystems - Beijing China }
700dd1de374Slin wang - Sun Microsystems - Beijing China 
701dd1de374Slin wang - Sun Microsystems - Beijing China static struct ath_hal *
702dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_do_attach(uint16_t device_id, struct arn_softc *sc,
703dd1de374Slin wang - Sun Microsystems - Beijing China     caddr_t mem, int *status)
704dd1de374Slin wang - Sun Microsystems - Beijing China {
705dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp;
706dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal *ah;
707dd1de374Slin wang - Sun Microsystems - Beijing China 	int ecode;
708dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t i;
709dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t j;
710dd1de374Slin wang - Sun Microsystems - Beijing China 
711dd1de374Slin wang - Sun Microsystems - Beijing China 	ahp = ath9k_hw_newstate(device_id, sc, mem, status);
712dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ahp == NULL)
713dd1de374Slin wang - Sun Microsystems - Beijing China 		return (NULL);
714dd1de374Slin wang - Sun Microsystems - Beijing China 
715dd1de374Slin wang - Sun Microsystems - Beijing China 	ah = &ahp->ah;
716dd1de374Slin wang - Sun Microsystems - Beijing China 
717dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_set_defaults(ah);
718dd1de374Slin wang - Sun Microsystems - Beijing China 
719dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ah->ah_config.intr_mitigation != 0)
720dd1de374Slin wang - Sun Microsystems - Beijing China 		ahp->ah_intrMitigation = B_TRUE;
721dd1de374Slin wang - Sun Microsystems - Beijing China 
722dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
723dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_HW, "arn: ath9k_hw_set_reset_reg(): "
724dd1de374Slin wang - Sun Microsystems - Beijing China 		    "couldn't reset chip \n"));
725dd1de374Slin wang - Sun Microsystems - Beijing China 		ecode = EIO;
726dd1de374Slin wang - Sun Microsystems - Beijing China 		goto bad;
727dd1de374Slin wang - Sun Microsystems - Beijing China 	}
728dd1de374Slin wang - Sun Microsystems - Beijing China 
729dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
730dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_HW, "arn: ath9k_hw_setpower(): "
731dd1de374Slin wang - Sun Microsystems - Beijing China 		    "couldn't wakeup chip \n"));
732dd1de374Slin wang - Sun Microsystems - Beijing China 		ecode = EIO;
733dd1de374Slin wang - Sun Microsystems - Beijing China 		goto bad;
734dd1de374Slin wang - Sun Microsystems - Beijing China 	}
735dd1de374Slin wang - Sun Microsystems - Beijing China 
736dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ah->ah_config.serialize_regmode == SER_REG_MODE_AUTO) {
737dd1de374Slin wang - Sun Microsystems - Beijing China 		if (ah->ah_macVersion == AR_SREV_VERSION_5416_PCI ||
738dd1de374Slin wang - Sun Microsystems - Beijing China 		    (AR_SREV_9280(ah) && !ah->ah_isPciExpress)) {
739dd1de374Slin wang - Sun Microsystems - Beijing China 			ah->ah_config.serialize_regmode =
740dd1de374Slin wang - Sun Microsystems - Beijing China 			    SER_REG_MODE_ON;
741dd1de374Slin wang - Sun Microsystems - Beijing China 		} else {
742dd1de374Slin wang - Sun Microsystems - Beijing China 			ah->ah_config.serialize_regmode =
743dd1de374Slin wang - Sun Microsystems - Beijing China 			    SER_REG_MODE_OFF;
744dd1de374Slin wang - Sun Microsystems - Beijing China 		}
745dd1de374Slin wang - Sun Microsystems - Beijing China 	}
746dd1de374Slin wang - Sun Microsystems - Beijing China 	ARN_DBG((ARN_DBG_HW, "arn: ath9k_hw_do_attach(): "
747dd1de374Slin wang - Sun Microsystems - Beijing China 	    "serialize_regmode is %d\n",
748dd1de374Slin wang - Sun Microsystems - Beijing China 	    ah->ah_config.serialize_regmode));
749dd1de374Slin wang - Sun Microsystems - Beijing China 
750dd1de374Slin wang - Sun Microsystems - Beijing China 	if ((ah->ah_macVersion != AR_SREV_VERSION_5416_PCI) &&
751dd1de374Slin wang - Sun Microsystems - Beijing China 	    (ah->ah_macVersion != AR_SREV_VERSION_5416_PCIE) &&
752dd1de374Slin wang - Sun Microsystems - Beijing China 	    (ah->ah_macVersion != AR_SREV_VERSION_9160) &&
753dd1de374Slin wang - Sun Microsystems - Beijing China 	    (!AR_SREV_9100(ah)) && (!AR_SREV_9280(ah)) &&
754dd1de374Slin wang - Sun Microsystems - Beijing China 	    (!AR_SREV_9285(ah))) {
755dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_HW, "arn: ath9k_hw_do_attach(): "
756dd1de374Slin wang - Sun Microsystems - Beijing China 		    "Mac Chip Rev 0x%02x.%x is not supported by this driver\n",
757dd1de374Slin wang - Sun Microsystems - Beijing China 		    ah->ah_macVersion, ah->ah_macRev));
758dd1de374Slin wang - Sun Microsystems - Beijing China 		ecode = ENOTSUP;
759dd1de374Slin wang - Sun Microsystems - Beijing China 		goto bad;
760dd1de374Slin wang - Sun Microsystems - Beijing China 	}
761dd1de374Slin wang - Sun Microsystems - Beijing China 
762dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9100(ah)) {
763dd1de374Slin wang - Sun Microsystems - Beijing China 		ahp->ah_iqCalData.calData = &iq_cal_multi_sample;
764dd1de374Slin wang - Sun Microsystems - Beijing China 		ahp->ah_suppCals = IQ_MISMATCH_CAL;
765dd1de374Slin wang - Sun Microsystems - Beijing China 		ah->ah_isPciExpress = B_FALSE;
766dd1de374Slin wang - Sun Microsystems - Beijing China 	}
767dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
768dd1de374Slin wang - Sun Microsystems - Beijing China 
769dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9160_10_OR_LATER(ah)) {
770dd1de374Slin wang - Sun Microsystems - Beijing China 		if (AR_SREV_9280_10_OR_LATER(ah)) {
771dd1de374Slin wang - Sun Microsystems - Beijing China 			ahp->ah_iqCalData.calData = &iq_cal_single_sample;
772dd1de374Slin wang - Sun Microsystems - Beijing China 			ahp->ah_adcGainCalData.calData =
773dd1de374Slin wang - Sun Microsystems - Beijing China 			    &adc_gain_cal_single_sample;
774dd1de374Slin wang - Sun Microsystems - Beijing China 			ahp->ah_adcDcCalData.calData =
775dd1de374Slin wang - Sun Microsystems - Beijing China 			    &adc_dc_cal_single_sample;
776dd1de374Slin wang - Sun Microsystems - Beijing China 			ahp->ah_adcDcCalInitData.calData =
777dd1de374Slin wang - Sun Microsystems - Beijing China 			    &adc_init_dc_cal;
778dd1de374Slin wang - Sun Microsystems - Beijing China 		} else {
779dd1de374Slin wang - Sun Microsystems - Beijing China 			ahp->ah_iqCalData.calData = &iq_cal_multi_sample;
780dd1de374Slin wang - Sun Microsystems - Beijing China 			ahp->ah_adcGainCalData.calData =
781dd1de374Slin wang - Sun Microsystems - Beijing China 			    &adc_gain_cal_multi_sample;
782dd1de374Slin wang - Sun Microsystems - Beijing China 			ahp->ah_adcDcCalData.calData =
783dd1de374Slin wang - Sun Microsystems - Beijing China 			    &adc_dc_cal_multi_sample;
784dd1de374Slin wang - Sun Microsystems - Beijing China 			ahp->ah_adcDcCalInitData.calData =
785dd1de374Slin wang - Sun Microsystems - Beijing China 			    &adc_init_dc_cal;
786dd1de374Slin wang - Sun Microsystems - Beijing China 		}
787dd1de374Slin wang - Sun Microsystems - Beijing China 		ahp->ah_suppCals = ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL;
788dd1de374Slin wang - Sun Microsystems - Beijing China 	}
789dd1de374Slin wang - Sun Microsystems - Beijing China 
790dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9160(ah)) {
791dd1de374Slin wang - Sun Microsystems - Beijing China 		ah->ah_config.enable_ani = 1;
792dd1de374Slin wang - Sun Microsystems - Beijing China 		ahp->ah_ani_function = (ATH9K_ANI_SPUR_IMMUNITY_LEVEL |
793dd1de374Slin wang - Sun Microsystems - Beijing China 		    ATH9K_ANI_FIRSTEP_LEVEL);
794dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
795dd1de374Slin wang - Sun Microsystems - Beijing China 		ahp->ah_ani_function = ATH9K_ANI_ALL;
796dd1de374Slin wang - Sun Microsystems - Beijing China 		if (AR_SREV_9280_10_OR_LATER(ah)) {
797dd1de374Slin wang - Sun Microsystems - Beijing China 			ahp->ah_ani_function &=
798dd1de374Slin wang - Sun Microsystems - Beijing China 			    ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
799dd1de374Slin wang - Sun Microsystems - Beijing China 		}
800dd1de374Slin wang - Sun Microsystems - Beijing China 	}
801dd1de374Slin wang - Sun Microsystems - Beijing China 	ARN_DBG((ARN_DBG_HW, "arn: ath9k_hw_do_attach(): "
802dd1de374Slin wang - Sun Microsystems - Beijing China 	    "This Mac Chip Rev 0x%02x.%x is \n",
803dd1de374Slin wang - Sun Microsystems - Beijing China 	    ah->ah_macVersion, ah->ah_macRev));
804dd1de374Slin wang - Sun Microsystems - Beijing China 
805dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9285_12_OR_LATER(ah)) {
806dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniModes, ar9285Modes_9285_1_2,
807dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar9285Modes_9285_1_2), 6);
808dd1de374Slin wang - Sun Microsystems - Beijing China 
809dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniCommon, ar9285Common_9285_1_2,
810dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar9285Common_9285_1_2), 2);
811dd1de374Slin wang - Sun Microsystems - Beijing China 
812dd1de374Slin wang - Sun Microsystems - Beijing China 		if (ah->ah_config.pcie_clock_req) {
813dd1de374Slin wang - Sun Microsystems - Beijing China 			INIT_INI_ARRAY(&ahp->ah_iniPcieSerdes,
814dd1de374Slin wang - Sun Microsystems - Beijing China 			    ar9285PciePhy_clkreq_off_L1_9285_1_2,
815dd1de374Slin wang - Sun Microsystems - Beijing China 			    ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285_1_2),
816dd1de374Slin wang - Sun Microsystems - Beijing China 			    2);
817dd1de374Slin wang - Sun Microsystems - Beijing China 		} else {
818dd1de374Slin wang - Sun Microsystems - Beijing China 			INIT_INI_ARRAY(&ahp->ah_iniPcieSerdes,
819dd1de374Slin wang - Sun Microsystems - Beijing China 			    ar9285PciePhy_clkreq_always_on_L1_9285_1_2,
820dd1de374Slin wang - Sun Microsystems - Beijing China 			    ARRAY_SIZE
821dd1de374Slin wang - Sun Microsystems - Beijing China 			    (ar9285PciePhy_clkreq_always_on_L1_9285_1_2), 2);
822dd1de374Slin wang - Sun Microsystems - Beijing China 		}
823dd1de374Slin wang - Sun Microsystems - Beijing China 	} else if (AR_SREV_9285_10_OR_LATER(ah)) {
824dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniModes, ar9285Modes_9285,
825dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar9285Modes_9285), 6);
826dd1de374Slin wang - Sun Microsystems - Beijing China 
827dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniCommon, ar9285Common_9285,
828dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar9285Common_9285), 2);
829dd1de374Slin wang - Sun Microsystems - Beijing China 
830dd1de374Slin wang - Sun Microsystems - Beijing China 		if (ah->ah_config.pcie_clock_req) {
831dd1de374Slin wang - Sun Microsystems - Beijing China 
832dd1de374Slin wang - Sun Microsystems - Beijing China 			INIT_INI_ARRAY(&ahp->ah_iniPcieSerdes,
833dd1de374Slin wang - Sun Microsystems - Beijing China 			    ar9285PciePhy_clkreq_off_L1_9285,
834dd1de374Slin wang - Sun Microsystems - Beijing China 			    ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285), 2);
835dd1de374Slin wang - Sun Microsystems - Beijing China 		} else {
836dd1de374Slin wang - Sun Microsystems - Beijing China 			INIT_INI_ARRAY(&ahp->ah_iniPcieSerdes,
837dd1de374Slin wang - Sun Microsystems - Beijing China 			    ar9285PciePhy_clkreq_always_on_L1_9285,
838dd1de374Slin wang - Sun Microsystems - Beijing China 			    ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285),
839dd1de374Slin wang - Sun Microsystems - Beijing China 			    2);
840dd1de374Slin wang - Sun Microsystems - Beijing China 		}
841dd1de374Slin wang - Sun Microsystems - Beijing China 	} else if (AR_SREV_9280_20_OR_LATER(ah)) {
842dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniModes, ar9280Modes_9280_2,
843dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar9280Modes_9280_2), 6);
844dd1de374Slin wang - Sun Microsystems - Beijing China 
845dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniCommon, ar9280Common_9280_2,
846dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar9280Common_9280_2), 2);
847dd1de374Slin wang - Sun Microsystems - Beijing China 
848dd1de374Slin wang - Sun Microsystems - Beijing China 		if (ah->ah_config.pcie_clock_req) {
849dd1de374Slin wang - Sun Microsystems - Beijing China 			INIT_INI_ARRAY(&ahp->ah_iniPcieSerdes,
850dd1de374Slin wang - Sun Microsystems - Beijing China 			    ar9280PciePhy_clkreq_off_L1_9280,
851dd1de374Slin wang - Sun Microsystems - Beijing China 			    ARRAY_SIZE(ar9280PciePhy_clkreq_off_L1_9280), 2);
852dd1de374Slin wang - Sun Microsystems - Beijing China 		} else {
853dd1de374Slin wang - Sun Microsystems - Beijing China 			INIT_INI_ARRAY(&ahp->ah_iniPcieSerdes,
854dd1de374Slin wang - Sun Microsystems - Beijing China 			    ar9280PciePhy_clkreq_always_on_L1_9280,
855dd1de374Slin wang - Sun Microsystems - Beijing China 			    ARRAY_SIZE
856dd1de374Slin wang - Sun Microsystems - Beijing China 			    (ar9280PciePhy_clkreq_always_on_L1_9280), 2);
857dd1de374Slin wang - Sun Microsystems - Beijing China 		}
858dd1de374Slin wang - Sun Microsystems - Beijing China 
859dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniModesAdditional,
860dd1de374Slin wang - Sun Microsystems - Beijing China 		    ar9280Modes_fast_clock_9280_2,
861dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar9280Modes_fast_clock_9280_2), 3);
862dd1de374Slin wang - Sun Microsystems - Beijing China 	} else if (AR_SREV_9280_10_OR_LATER(ah)) {
863dd1de374Slin wang - Sun Microsystems - Beijing China 
864dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniModes, ar9280Modes_9280,
865dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar9280Modes_9280), 6);
866dd1de374Slin wang - Sun Microsystems - Beijing China 
867dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniCommon, ar9280Common_9280,
868dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar9280Common_9280), 2);
869dd1de374Slin wang - Sun Microsystems - Beijing China 	} else if (AR_SREV_9160_10_OR_LATER(ah)) {
870dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniModes, ar5416Modes_9160,
871dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar5416Modes_9160), 6);
872dd1de374Slin wang - Sun Microsystems - Beijing China 
873dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniCommon, ar5416Common_9160,
874dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar5416Common_9160), 2);
875dd1de374Slin wang - Sun Microsystems - Beijing China 
876dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniBank0, ar5416Bank0_9160,
877dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar5416Bank0_9160), 2);
878dd1de374Slin wang - Sun Microsystems - Beijing China 
879dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniBB_RfGain, ar5416BB_RfGain_9160,
880dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar5416BB_RfGain_9160), 3);
881dd1de374Slin wang - Sun Microsystems - Beijing China 
882dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniBank1, ar5416Bank1_9160,
883dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar5416Bank1_9160), 2);
884dd1de374Slin wang - Sun Microsystems - Beijing China 
885dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniBank2, ar5416Bank2_9160,
886dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar5416Bank2_9160), 2);
887dd1de374Slin wang - Sun Microsystems - Beijing China 
888dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniBank3, ar5416Bank3_9160,
889dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar5416Bank3_9160), 3);
890dd1de374Slin wang - Sun Microsystems - Beijing China 
891dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniBank6, ar5416Bank6_9160,
892dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar5416Bank6_9160), 3);
893dd1de374Slin wang - Sun Microsystems - Beijing China 
894dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniBank6TPC, ar5416Bank6TPC_9160,
895dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar5416Bank6TPC_9160), 3);
896dd1de374Slin wang - Sun Microsystems - Beijing China 
897dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniBank7, ar5416Bank7_9160,
898dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar5416Bank7_9160), 2);
899dd1de374Slin wang - Sun Microsystems - Beijing China 		if (AR_SREV_9160_11(ah)) {
900dd1de374Slin wang - Sun Microsystems - Beijing China 			INIT_INI_ARRAY(&ahp->ah_iniAddac,
901dd1de374Slin wang - Sun Microsystems - Beijing China 			    ar5416Addac_91601_1,
902dd1de374Slin wang - Sun Microsystems - Beijing China 			    ARRAY_SIZE(ar5416Addac_91601_1), 2);
903dd1de374Slin wang - Sun Microsystems - Beijing China 		} else {
904dd1de374Slin wang - Sun Microsystems - Beijing China 			INIT_INI_ARRAY(&ahp->ah_iniAddac, ar5416Addac_9160,
905dd1de374Slin wang - Sun Microsystems - Beijing China 			    ARRAY_SIZE(ar5416Addac_9160), 2);
906dd1de374Slin wang - Sun Microsystems - Beijing China 		}
907dd1de374Slin wang - Sun Microsystems - Beijing China 	} else if (AR_SREV_9100_OR_LATER(ah)) {
908dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniModes, ar5416Modes_9100,
909dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar5416Modes_9100), 6);
910dd1de374Slin wang - Sun Microsystems - Beijing China 
911dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniCommon, ar5416Common_9100,
912dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar5416Common_9100), 2);
913dd1de374Slin wang - Sun Microsystems - Beijing China 
914dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniBank0, ar5416Bank0_9100,
915dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar5416Bank0_9100), 2);
916dd1de374Slin wang - Sun Microsystems - Beijing China 
917dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniBB_RfGain, ar5416BB_RfGain_9100,
918dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar5416BB_RfGain_9100), 3);
919dd1de374Slin wang - Sun Microsystems - Beijing China 
920dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniBank1, ar5416Bank1_9100,
921dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar5416Bank1_9100), 2);
922dd1de374Slin wang - Sun Microsystems - Beijing China 
923dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniBank2, ar5416Bank2_9100,
924dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar5416Bank2_9100), 2);
925dd1de374Slin wang - Sun Microsystems - Beijing China 
926dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniBank3, ar5416Bank3_9100,
927dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar5416Bank3_9100), 3);
928dd1de374Slin wang - Sun Microsystems - Beijing China 
929dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniBank6, ar5416Bank6_9100,
930dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar5416Bank6_9100), 3);
931dd1de374Slin wang - Sun Microsystems - Beijing China 
932dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniBank6TPC, ar5416Bank6TPC_9100,
933dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar5416Bank6TPC_9100), 3);
934dd1de374Slin wang - Sun Microsystems - Beijing China 
935dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniBank7, ar5416Bank7_9100,
936dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar5416Bank7_9100), 2);
937dd1de374Slin wang - Sun Microsystems - Beijing China 
938dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniAddac, ar5416Addac_9100,
939dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar5416Addac_9100), 2);
940dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
941dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniModes, ar5416Modes,
942dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar5416Modes), 6);
943dd1de374Slin wang - Sun Microsystems - Beijing China 
944dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniCommon, ar5416Common,
945dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar5416Common), 2);
946dd1de374Slin wang - Sun Microsystems - Beijing China 
947dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniBank0, ar5416Bank0,
948dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar5416Bank0), 2);
949dd1de374Slin wang - Sun Microsystems - Beijing China 
950dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniBB_RfGain, ar5416BB_RfGain,
951dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar5416BB_RfGain), 3);
952dd1de374Slin wang - Sun Microsystems - Beijing China 
953dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniBank1, ar5416Bank1,
954dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar5416Bank1), 2);
955dd1de374Slin wang - Sun Microsystems - Beijing China 
956dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniBank2, ar5416Bank2,
957dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar5416Bank2), 2);
958dd1de374Slin wang - Sun Microsystems - Beijing China 
959dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniBank3, ar5416Bank3,
960dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar5416Bank3), 3);
961dd1de374Slin wang - Sun Microsystems - Beijing China 
962dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniBank6, ar5416Bank6,
963dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar5416Bank6), 3);
964dd1de374Slin wang - Sun Microsystems - Beijing China 
965dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniBank6TPC, ar5416Bank6TPC,
966dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar5416Bank6TPC), 3);
967dd1de374Slin wang - Sun Microsystems - Beijing China 
968dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniBank7, ar5416Bank7,
969dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar5416Bank7), 2);
970dd1de374Slin wang - Sun Microsystems - Beijing China 
971dd1de374Slin wang - Sun Microsystems - Beijing China 		INIT_INI_ARRAY(&ahp->ah_iniAddac, ar5416Addac,
972dd1de374Slin wang - Sun Microsystems - Beijing China 		    ARRAY_SIZE(ar5416Addac), 2);
973dd1de374Slin wang - Sun Microsystems - Beijing China 	}
974dd1de374Slin wang - Sun Microsystems - Beijing China 
975dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ah->ah_isPciExpress)
976dd1de374Slin wang - Sun Microsystems - Beijing China 		ath9k_hw_configpcipowersave(ah, 0);
977dd1de374Slin wang - Sun Microsystems - Beijing China 	else
978dd1de374Slin wang - Sun Microsystems - Beijing China 		ath9k_hw_disablepcie(ah);
979dd1de374Slin wang - Sun Microsystems - Beijing China 
980dd1de374Slin wang - Sun Microsystems - Beijing China 	ecode = ath9k_hw_post_attach(ah);
981dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ecode != 0)
982dd1de374Slin wang - Sun Microsystems - Beijing China 		goto bad;
983dd1de374Slin wang - Sun Microsystems - Beijing China 
984dd1de374Slin wang - Sun Microsystems - Beijing China 	/* rxgain table */
985dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9280_20(ah))
986dd1de374Slin wang - Sun Microsystems - Beijing China 		ath9k_hw_init_rxgain_ini(ah);
987dd1de374Slin wang - Sun Microsystems - Beijing China 
988dd1de374Slin wang - Sun Microsystems - Beijing China 	/* txgain table */
989dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9280_20(ah))
990dd1de374Slin wang - Sun Microsystems - Beijing China 		ath9k_hw_init_txgain_ini(ah);
991dd1de374Slin wang - Sun Microsystems - Beijing China 
992dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ah->ah_devid == AR9280_DEVID_PCI) {
993dd1de374Slin wang - Sun Microsystems - Beijing China 		for (i = 0; i < ahp->ah_iniModes.ia_rows; i++) {
994dd1de374Slin wang - Sun Microsystems - Beijing China 			uint32_t reg =
995dd1de374Slin wang - Sun Microsystems - Beijing China 			    INI_RA(&ahp->ah_iniModes, i, 0);
996dd1de374Slin wang - Sun Microsystems - Beijing China 
997dd1de374Slin wang - Sun Microsystems - Beijing China 			for (j = 1; j < ahp->ah_iniModes.ia_columns; j++) {
998dd1de374Slin wang - Sun Microsystems - Beijing China 				uint32_t val
999dd1de374Slin wang - Sun Microsystems - Beijing China 				    = INI_RA(&ahp->ah_iniModes, i, j);
1000dd1de374Slin wang - Sun Microsystems - Beijing China 
1001dd1de374Slin wang - Sun Microsystems - Beijing China 				INI_RA(&ahp->ah_iniModes, i, j) =
1002dd1de374Slin wang - Sun Microsystems - Beijing China 				    ath9k_hw_ini_fixup(ah, &ahp->ah_eeprom.def,
1003dd1de374Slin wang - Sun Microsystems - Beijing China 				    reg, val);
1004dd1de374Slin wang - Sun Microsystems - Beijing China 			}
1005dd1de374Slin wang - Sun Microsystems - Beijing China 		}
1006dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1007dd1de374Slin wang - Sun Microsystems - Beijing China 
1008dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!ath9k_hw_fill_cap_info(ah)) {
1009dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_HW, "arn: ath9k_hw_do_attach(): "
1010dd1de374Slin wang - Sun Microsystems - Beijing China 		    "failed ath9k_hw_fill_cap_info\n"));
1011dd1de374Slin wang - Sun Microsystems - Beijing China 		goto bad;
1012dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1013dd1de374Slin wang - Sun Microsystems - Beijing China 
1014dd1de374Slin wang - Sun Microsystems - Beijing China 	ecode = ath9k_hw_init_macaddr(ah);
1015dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ecode != 0) {
1016dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_HW, "arn: "
1017dd1de374Slin wang - Sun Microsystems - Beijing China 		    "%s: failed initializing mac address\n",
1018dd1de374Slin wang - Sun Microsystems - Beijing China 		    __func__));
1019dd1de374Slin wang - Sun Microsystems - Beijing China 		goto bad;
1020dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1021dd1de374Slin wang - Sun Microsystems - Beijing China 
1022dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9285(ah))
1023dd1de374Slin wang - Sun Microsystems - Beijing China 		ah->ah_txTrigLevel = (AR_FTRIG_256B >> AR_FTRIG_S);
1024dd1de374Slin wang - Sun Microsystems - Beijing China 	else
1025dd1de374Slin wang - Sun Microsystems - Beijing China 		ah->ah_txTrigLevel = (AR_FTRIG_512B >> AR_FTRIG_S);
1026dd1de374Slin wang - Sun Microsystems - Beijing China 
1027dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_init_nfcal_hist_buffer(ah);
1028dd1de374Slin wang - Sun Microsystems - Beijing China 
1029dd1de374Slin wang - Sun Microsystems - Beijing China 	return (ah);
1030dd1de374Slin wang - Sun Microsystems - Beijing China bad:
1031dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ahp)
1032dd1de374Slin wang - Sun Microsystems - Beijing China 		ath9k_hw_detach((struct ath_hal *)ahp);
1033dd1de374Slin wang - Sun Microsystems - Beijing China 	if (status)
1034dd1de374Slin wang - Sun Microsystems - Beijing China 		*status = ecode;
1035dd1de374Slin wang - Sun Microsystems - Beijing China 
1036dd1de374Slin wang - Sun Microsystems - Beijing China 	return (NULL);
1037dd1de374Slin wang - Sun Microsystems - Beijing China }
1038dd1de374Slin wang - Sun Microsystems - Beijing China 
1039dd1de374Slin wang - Sun Microsystems - Beijing China static void
1040dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_init_bb(struct ath_hal *ah, struct ath9k_channel *chan)
1041dd1de374Slin wang - Sun Microsystems - Beijing China {
1042dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t synthDelay;
1043dd1de374Slin wang - Sun Microsystems - Beijing China 
1044dd1de374Slin wang - Sun Microsystems - Beijing China 	synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
1045dd1de374Slin wang - Sun Microsystems - Beijing China 	if (IS_CHAN_B(chan))
1046dd1de374Slin wang - Sun Microsystems - Beijing China 		synthDelay = (4 * synthDelay) / 22;
1047dd1de374Slin wang - Sun Microsystems - Beijing China 	else
1048dd1de374Slin wang - Sun Microsystems - Beijing China 		synthDelay /= 10;
1049dd1de374Slin wang - Sun Microsystems - Beijing China 
1050dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
1051dd1de374Slin wang - Sun Microsystems - Beijing China 
1052dd1de374Slin wang - Sun Microsystems - Beijing China 	drv_usecwait(synthDelay + BASE_ACTIVATE_DELAY);
1053dd1de374Slin wang - Sun Microsystems - Beijing China }
1054dd1de374Slin wang - Sun Microsystems - Beijing China 
1055dd1de374Slin wang - Sun Microsystems - Beijing China static void
1056dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_init_qos(struct ath_hal *ah)
1057dd1de374Slin wang - Sun Microsystems - Beijing China {
1058dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
1059dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
1060dd1de374Slin wang - Sun Microsystems - Beijing China 
1061dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_QOS_NO_ACK,
1062dd1de374Slin wang - Sun Microsystems - Beijing China 	    SM(2, AR_QOS_NO_ACK_TWO_BIT) |
1063dd1de374Slin wang - Sun Microsystems - Beijing China 	    SM(5, AR_QOS_NO_ACK_BIT_OFF) |
1064dd1de374Slin wang - Sun Microsystems - Beijing China 	    SM(0, AR_QOS_NO_ACK_BYTE_OFF));
1065dd1de374Slin wang - Sun Microsystems - Beijing China 
1066dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
1067dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
1068dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
1069dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
1070dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
1071dd1de374Slin wang - Sun Microsystems - Beijing China }
1072dd1de374Slin wang - Sun Microsystems - Beijing China 
1073dd1de374Slin wang - Sun Microsystems - Beijing China static void
1074dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_init_pll(struct ath_hal *ah, struct ath9k_channel *chan)
1075dd1de374Slin wang - Sun Microsystems - Beijing China {
1076dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t pll;
1077dd1de374Slin wang - Sun Microsystems - Beijing China 
1078dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9100(ah)) {
1079dd1de374Slin wang - Sun Microsystems - Beijing China 		if (chan && IS_CHAN_5GHZ(chan))
1080dd1de374Slin wang - Sun Microsystems - Beijing China 			pll = 0x1450;
1081dd1de374Slin wang - Sun Microsystems - Beijing China 		else
1082dd1de374Slin wang - Sun Microsystems - Beijing China 			pll = 0x1458;
1083dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
1084dd1de374Slin wang - Sun Microsystems - Beijing China 		if (AR_SREV_9280_10_OR_LATER(ah)) {
1085dd1de374Slin wang - Sun Microsystems - Beijing China 			pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
1086dd1de374Slin wang - Sun Microsystems - Beijing China 
1087dd1de374Slin wang - Sun Microsystems - Beijing China 			if (chan && IS_CHAN_HALF_RATE(chan))
1088dd1de374Slin wang - Sun Microsystems - Beijing China 				pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
1089dd1de374Slin wang - Sun Microsystems - Beijing China 			else if (chan && IS_CHAN_QUARTER_RATE(chan))
1090dd1de374Slin wang - Sun Microsystems - Beijing China 				pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
1091dd1de374Slin wang - Sun Microsystems - Beijing China 
1092dd1de374Slin wang - Sun Microsystems - Beijing China 			if (chan && IS_CHAN_5GHZ(chan)) {
1093dd1de374Slin wang - Sun Microsystems - Beijing China 				pll |= SM(0x28, AR_RTC_9160_PLL_DIV);
1094dd1de374Slin wang - Sun Microsystems - Beijing China 
1095dd1de374Slin wang - Sun Microsystems - Beijing China 
1096dd1de374Slin wang - Sun Microsystems - Beijing China 				if (AR_SREV_9280_20(ah)) {
1097dd1de374Slin wang - Sun Microsystems - Beijing China 					if (((chan->channel % 20) == 0) ||
1098dd1de374Slin wang - Sun Microsystems - Beijing China 					    ((chan->channel % 10) == 0))
1099dd1de374Slin wang - Sun Microsystems - Beijing China 						pll = 0x2850;
1100dd1de374Slin wang - Sun Microsystems - Beijing China 					else
1101dd1de374Slin wang - Sun Microsystems - Beijing China 						pll = 0x142c;
1102dd1de374Slin wang - Sun Microsystems - Beijing China 				}
1103dd1de374Slin wang - Sun Microsystems - Beijing China 			} else {
1104dd1de374Slin wang - Sun Microsystems - Beijing China 				pll |= SM(0x2c, AR_RTC_9160_PLL_DIV);
1105dd1de374Slin wang - Sun Microsystems - Beijing China 			}
1106dd1de374Slin wang - Sun Microsystems - Beijing China 
1107dd1de374Slin wang - Sun Microsystems - Beijing China 		} else if (AR_SREV_9160_10_OR_LATER(ah)) {
1108dd1de374Slin wang - Sun Microsystems - Beijing China 
1109dd1de374Slin wang - Sun Microsystems - Beijing China 			pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
1110dd1de374Slin wang - Sun Microsystems - Beijing China 
1111dd1de374Slin wang - Sun Microsystems - Beijing China 			if (chan && IS_CHAN_HALF_RATE(chan))
1112dd1de374Slin wang - Sun Microsystems - Beijing China 				pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
1113dd1de374Slin wang - Sun Microsystems - Beijing China 			else if (chan && IS_CHAN_QUARTER_RATE(chan))
1114dd1de374Slin wang - Sun Microsystems - Beijing China 				pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
1115dd1de374Slin wang - Sun Microsystems - Beijing China 
1116dd1de374Slin wang - Sun Microsystems - Beijing China 			if (chan && IS_CHAN_5GHZ(chan))
1117dd1de374Slin wang - Sun Microsystems - Beijing China 				pll |= SM(0x50, AR_RTC_9160_PLL_DIV);
1118dd1de374Slin wang - Sun Microsystems - Beijing China 			else
1119dd1de374Slin wang - Sun Microsystems - Beijing China 				pll |= SM(0x58, AR_RTC_9160_PLL_DIV);
1120dd1de374Slin wang - Sun Microsystems - Beijing China 		} else {
1121dd1de374Slin wang - Sun Microsystems - Beijing China 			pll = AR_RTC_PLL_REFDIV_5 | AR_RTC_PLL_DIV2;
1122dd1de374Slin wang - Sun Microsystems - Beijing China 
1123dd1de374Slin wang - Sun Microsystems - Beijing China 			if (chan && IS_CHAN_HALF_RATE(chan))
1124dd1de374Slin wang - Sun Microsystems - Beijing China 				pll |= SM(0x1, AR_RTC_PLL_CLKSEL);
1125dd1de374Slin wang - Sun Microsystems - Beijing China 			else if (chan && IS_CHAN_QUARTER_RATE(chan))
1126dd1de374Slin wang - Sun Microsystems - Beijing China 				pll |= SM(0x2, AR_RTC_PLL_CLKSEL);
1127dd1de374Slin wang - Sun Microsystems - Beijing China 
1128dd1de374Slin wang - Sun Microsystems - Beijing China 			if (chan && IS_CHAN_5GHZ(chan))
1129dd1de374Slin wang - Sun Microsystems - Beijing China 				pll |= SM(0xa, AR_RTC_PLL_DIV);
1130dd1de374Slin wang - Sun Microsystems - Beijing China 			else
1131dd1de374Slin wang - Sun Microsystems - Beijing China 				pll |= SM(0xb, AR_RTC_PLL_DIV);
1132dd1de374Slin wang - Sun Microsystems - Beijing China 		}
1133dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1134dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, (uint16_t)(AR_RTC_PLL_CONTROL), pll);
1135dd1de374Slin wang - Sun Microsystems - Beijing China 
1136dd1de374Slin wang - Sun Microsystems - Beijing China 	drv_usecwait(RTC_PLL_SETTLE_DELAY);
1137dd1de374Slin wang - Sun Microsystems - Beijing China 
1138dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
1139dd1de374Slin wang - Sun Microsystems - Beijing China }
1140dd1de374Slin wang - Sun Microsystems - Beijing China 
1141dd1de374Slin wang - Sun Microsystems - Beijing China static void
1142dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_init_chain_masks(struct ath_hal *ah)
1143dd1de374Slin wang - Sun Microsystems - Beijing China {
1144dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
1145dd1de374Slin wang - Sun Microsystems - Beijing China 	int rx_chainmask, tx_chainmask;
1146dd1de374Slin wang - Sun Microsystems - Beijing China 
1147dd1de374Slin wang - Sun Microsystems - Beijing China 	rx_chainmask = ahp->ah_rxchainmask;
1148dd1de374Slin wang - Sun Microsystems - Beijing China 	tx_chainmask = ahp->ah_txchainmask;
1149dd1de374Slin wang - Sun Microsystems - Beijing China 
1150dd1de374Slin wang - Sun Microsystems - Beijing China 	switch (rx_chainmask) {
1151dd1de374Slin wang - Sun Microsystems - Beijing China 	case 0x5:
1152dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
1153dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_PHY_SWAP_ALT_CHAIN);
1154dd1de374Slin wang - Sun Microsystems - Beijing China 		/*FALLTHRU*/
1155dd1de374Slin wang - Sun Microsystems - Beijing China 	case 0x3:
1156dd1de374Slin wang - Sun Microsystems - Beijing China 		if (((ah)->ah_macVersion <= AR_SREV_VERSION_9160)) {
1157dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_WRITE(ah, AR_PHY_RX_CHAINMASK, 0x7);
1158dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, 0x7);
1159dd1de374Slin wang - Sun Microsystems - Beijing China 			break;
1160dd1de374Slin wang - Sun Microsystems - Beijing China 		}
1161dd1de374Slin wang - Sun Microsystems - Beijing China 		/*FALLTHRU*/
1162dd1de374Slin wang - Sun Microsystems - Beijing China 	case 0x1:
1163dd1de374Slin wang - Sun Microsystems - Beijing China 	case 0x2:
1164dd1de374Slin wang - Sun Microsystems - Beijing China 	case 0x7:
1165dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
1166dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
1167dd1de374Slin wang - Sun Microsystems - Beijing China 		break;
1168dd1de374Slin wang - Sun Microsystems - Beijing China 	default:
1169dd1de374Slin wang - Sun Microsystems - Beijing China 		break;
1170dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1171dd1de374Slin wang - Sun Microsystems - Beijing China 
1172dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_SELFGEN_MASK, tx_chainmask);
1173dd1de374Slin wang - Sun Microsystems - Beijing China 	if (tx_chainmask == 0x5) {
1174dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
1175dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_PHY_SWAP_ALT_CHAIN);
1176dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1177dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9100(ah))
1178dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PHY_ANALOG_SWAP,
1179dd1de374Slin wang - Sun Microsystems - Beijing China 		    REG_READ(ah, AR_PHY_ANALOG_SWAP) | 0x00000001);
1180dd1de374Slin wang - Sun Microsystems - Beijing China }
1181dd1de374Slin wang - Sun Microsystems - Beijing China 
1182dd1de374Slin wang - Sun Microsystems - Beijing China static void
1183dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_init_interrupt_masks(struct ath_hal *ah, enum ath9k_opmode opmode)
1184dd1de374Slin wang - Sun Microsystems - Beijing China {
1185dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
1186dd1de374Slin wang - Sun Microsystems - Beijing China 
1187dd1de374Slin wang - Sun Microsystems - Beijing China 	ahp->ah_maskReg = AR_IMR_TXERR |
1188dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_IMR_TXURN |
1189dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_IMR_RXERR |
1190dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_IMR_RXORN |
1191dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_IMR_BCNMISC;
1192dd1de374Slin wang - Sun Microsystems - Beijing China 
1193dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ahp->ah_intrMitigation)
1194dd1de374Slin wang - Sun Microsystems - Beijing China 		ahp->ah_maskReg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
1195dd1de374Slin wang - Sun Microsystems - Beijing China 	else
1196dd1de374Slin wang - Sun Microsystems - Beijing China 		ahp->ah_maskReg |= AR_IMR_RXOK;
1197dd1de374Slin wang - Sun Microsystems - Beijing China 
1198dd1de374Slin wang - Sun Microsystems - Beijing China 	ahp->ah_maskReg |= AR_IMR_TXOK;
1199dd1de374Slin wang - Sun Microsystems - Beijing China 
1200dd1de374Slin wang - Sun Microsystems - Beijing China 	if (opmode == ATH9K_M_HOSTAP)
1201dd1de374Slin wang - Sun Microsystems - Beijing China 		ahp->ah_maskReg |= AR_IMR_MIB;
1202dd1de374Slin wang - Sun Microsystems - Beijing China 
1203dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_IMR, ahp->ah_maskReg);
1204dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_IMR_S2, REG_READ(ah, AR_IMR_S2) | AR_IMR_S2_GTT);
1205dd1de374Slin wang - Sun Microsystems - Beijing China 
1206dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!AR_SREV_9100(ah)) {
1207dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
1208dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT);
1209dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
1210dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1211dd1de374Slin wang - Sun Microsystems - Beijing China }
1212dd1de374Slin wang - Sun Microsystems - Beijing China 
1213dd1de374Slin wang - Sun Microsystems - Beijing China static boolean_t
1214dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_set_ack_timeout(struct ath_hal *ah, uint32_t us)
1215dd1de374Slin wang - Sun Microsystems - Beijing China {
1216dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
1217dd1de374Slin wang - Sun Microsystems - Beijing China 
1218dd1de374Slin wang - Sun Microsystems - Beijing China 	if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_ACK))) {
1219dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_HW, "arn: ath9k_hw_set_ack_timeout(): "
1220dd1de374Slin wang - Sun Microsystems - Beijing China 		    "bad ack timeout %u\n", us));
1221dd1de374Slin wang - Sun Microsystems - Beijing China 
1222dd1de374Slin wang - Sun Microsystems - Beijing China 		ahp->ah_acktimeout = (uint32_t)-1;
1223dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_FALSE);
1224dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
1225dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_RMW_FIELD(ah, AR_TIME_OUT,
1226dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_TIME_OUT_ACK, ath9k_hw_mac_to_clks(ah, us));
1227dd1de374Slin wang - Sun Microsystems - Beijing China 		ahp->ah_acktimeout = us;
1228dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_TRUE);
1229dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1230dd1de374Slin wang - Sun Microsystems - Beijing China }
1231dd1de374Slin wang - Sun Microsystems - Beijing China 
1232dd1de374Slin wang - Sun Microsystems - Beijing China static boolean_t
1233dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_set_cts_timeout(struct ath_hal *ah, uint32_t us)
1234dd1de374Slin wang - Sun Microsystems - Beijing China {
1235dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
1236dd1de374Slin wang - Sun Microsystems - Beijing China 
1237dd1de374Slin wang - Sun Microsystems - Beijing China 	if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_CTS))) {
1238dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_HW, "arn: ath9k_hw_set_cts_timeout(): "
1239dd1de374Slin wang - Sun Microsystems - Beijing China 		    "bad cts timeout %u\n", us));
1240dd1de374Slin wang - Sun Microsystems - Beijing China 
1241dd1de374Slin wang - Sun Microsystems - Beijing China 		ahp->ah_ctstimeout = (uint32_t)-1;
1242dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_FALSE);
1243dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
1244dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_RMW_FIELD(ah, AR_TIME_OUT,
1245dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_TIME_OUT_CTS, ath9k_hw_mac_to_clks(ah, us));
1246dd1de374Slin wang - Sun Microsystems - Beijing China 		ahp->ah_ctstimeout = us;
1247dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_TRUE);
1248dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1249dd1de374Slin wang - Sun Microsystems - Beijing China }
1250dd1de374Slin wang - Sun Microsystems - Beijing China 
1251dd1de374Slin wang - Sun Microsystems - Beijing China static boolean_t
1252dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_set_global_txtimeout(struct ath_hal *ah, uint32_t tu)
1253dd1de374Slin wang - Sun Microsystems - Beijing China {
1254dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
1255dd1de374Slin wang - Sun Microsystems - Beijing China 
1256dd1de374Slin wang - Sun Microsystems - Beijing China 	if (tu > 0xFFFF) {
1257dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_XMIT,
1258dd1de374Slin wang - Sun Microsystems - Beijing China 		    "arn: ath9k_hw_set_global_txtimeout(): "
1259dd1de374Slin wang - Sun Microsystems - Beijing China 		    "ath9k_hw_set_global_txtimeout\n", tu));
1260dd1de374Slin wang - Sun Microsystems - Beijing China 
1261dd1de374Slin wang - Sun Microsystems - Beijing China 		ahp->ah_globaltxtimeout = (uint32_t)-1;
1262dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_FALSE);
1263dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
1264dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
1265dd1de374Slin wang - Sun Microsystems - Beijing China 		ahp->ah_globaltxtimeout = tu;
1266dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_TRUE);
1267dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1268dd1de374Slin wang - Sun Microsystems - Beijing China }
1269dd1de374Slin wang - Sun Microsystems - Beijing China 
1270dd1de374Slin wang - Sun Microsystems - Beijing China static void
1271dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_init_user_settings(struct ath_hal *ah)
1272dd1de374Slin wang - Sun Microsystems - Beijing China {
1273dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
1274dd1de374Slin wang - Sun Microsystems - Beijing China 
1275dd1de374Slin wang - Sun Microsystems - Beijing China 	ARN_DBG((ARN_DBG_ANY, "arn: ath9k_hw_init_user_settings(): "
1276dd1de374Slin wang - Sun Microsystems - Beijing China 	    "--AP ahp->ah_miscMode 0x%x\n", ahp->ah_miscMode));
1277dd1de374Slin wang - Sun Microsystems - Beijing China 
1278dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ahp->ah_miscMode != 0)
1279dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PCU_MISC,
1280dd1de374Slin wang - Sun Microsystems - Beijing China 		    REG_READ(ah, AR_PCU_MISC) | ahp->ah_miscMode);
1281dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ahp->ah_slottime != (uint32_t)-1)
1282dd1de374Slin wang - Sun Microsystems - Beijing China 		(void) ath9k_hw_setslottime(ah, ahp->ah_slottime);
1283dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ahp->ah_acktimeout != (uint32_t)-1)
1284dd1de374Slin wang - Sun Microsystems - Beijing China 		(void) ath9k_hw_set_ack_timeout(ah, ahp->ah_acktimeout);
1285dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ahp->ah_ctstimeout != (uint32_t)-1)
1286dd1de374Slin wang - Sun Microsystems - Beijing China 		(void) ath9k_hw_set_cts_timeout(ah, ahp->ah_ctstimeout);
1287dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ahp->ah_globaltxtimeout != (uint32_t)-1)
1288dd1de374Slin wang - Sun Microsystems - Beijing China 		(void) ath9k_hw_set_global_txtimeout
1289dd1de374Slin wang - Sun Microsystems - Beijing China 		    (ah, ahp->ah_globaltxtimeout);
1290dd1de374Slin wang - Sun Microsystems - Beijing China }
1291dd1de374Slin wang - Sun Microsystems - Beijing China 
1292dd1de374Slin wang - Sun Microsystems - Beijing China const char *
1293dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_probe(uint16_t vendorid, uint16_t devid)
1294dd1de374Slin wang - Sun Microsystems - Beijing China {
1295dd1de374Slin wang - Sun Microsystems - Beijing China 	return (vendorid == ATHEROS_VENDOR_ID ?
1296dd1de374Slin wang - Sun Microsystems - Beijing China 	    ath9k_hw_devname(devid) : NULL);
1297dd1de374Slin wang - Sun Microsystems - Beijing China }
1298dd1de374Slin wang - Sun Microsystems - Beijing China 
1299dd1de374Slin wang - Sun Microsystems - Beijing China void
1300dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_detach(struct ath_hal *ah)
1301dd1de374Slin wang - Sun Microsystems - Beijing China {
1302dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!AR_SREV_9100(ah))
1303dd1de374Slin wang - Sun Microsystems - Beijing China 		ath9k_hw_ani_detach(ah);
1304dd1de374Slin wang - Sun Microsystems - Beijing China 
1305dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_rfdetach(ah);
1306dd1de374Slin wang - Sun Microsystems - Beijing China 	(void) ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
1307dd1de374Slin wang - Sun Microsystems - Beijing China 	kmem_free(ah, sizeof (struct ath_hal_5416)); /* ???? */
1308dd1de374Slin wang - Sun Microsystems - Beijing China }
1309dd1de374Slin wang - Sun Microsystems - Beijing China 
1310dd1de374Slin wang - Sun Microsystems - Beijing China struct ath_hal *
1311dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_attach(uint16_t device_id, struct arn_softc *sc,
1312dd1de374Slin wang - Sun Microsystems - Beijing China     caddr_t mem, int *error)
1313dd1de374Slin wang - Sun Microsystems - Beijing China {
1314dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal *ah = NULL;
1315dd1de374Slin wang - Sun Microsystems - Beijing China 
1316dd1de374Slin wang - Sun Microsystems - Beijing China 	switch (device_id) {
1317dd1de374Slin wang - Sun Microsystems - Beijing China 	case AR5416_DEVID_PCI:
1318dd1de374Slin wang - Sun Microsystems - Beijing China 	case AR5416_DEVID_PCIE:
1319dd1de374Slin wang - Sun Microsystems - Beijing China 	case AR9160_DEVID_PCI:
1320dd1de374Slin wang - Sun Microsystems - Beijing China 	case AR9280_DEVID_PCI:
1321dd1de374Slin wang - Sun Microsystems - Beijing China 	case AR9280_DEVID_PCIE:
1322dd1de374Slin wang - Sun Microsystems - Beijing China 	case AR9285_DEVID_PCIE:
1323dd1de374Slin wang - Sun Microsystems - Beijing China 		ah = ath9k_hw_do_attach(device_id, sc, mem, error);
1324dd1de374Slin wang - Sun Microsystems - Beijing China 		break;
1325dd1de374Slin wang - Sun Microsystems - Beijing China 	default:
1326dd1de374Slin wang - Sun Microsystems - Beijing China 		*error = ENXIO;
1327dd1de374Slin wang - Sun Microsystems - Beijing China 		break;
1328dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1329dd1de374Slin wang - Sun Microsystems - Beijing China 
1330dd1de374Slin wang - Sun Microsystems - Beijing China 	return (ah);
1331dd1de374Slin wang - Sun Microsystems - Beijing China }
1332dd1de374Slin wang - Sun Microsystems - Beijing China 
1333dd1de374Slin wang - Sun Microsystems - Beijing China /* INI */
1334dd1de374Slin wang - Sun Microsystems - Beijing China 
1335dd1de374Slin wang - Sun Microsystems - Beijing China /* ARGSUSED */
1336dd1de374Slin wang - Sun Microsystems - Beijing China static void
1337dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_override_ini(struct ath_hal *ah, struct ath9k_channel *chan)
1338dd1de374Slin wang - Sun Microsystems - Beijing China {
1339dd1de374Slin wang - Sun Microsystems - Beijing China 	/*
1340dd1de374Slin wang - Sun Microsystems - Beijing China 	 * Set the RX_ABORT and RX_DIS and clear if off only after
1341dd1de374Slin wang - Sun Microsystems - Beijing China 	 * RXE is set for MAC. This prevents frames with corrupted
1342dd1de374Slin wang - Sun Microsystems - Beijing China 	 * descriptor status.
1343dd1de374Slin wang - Sun Microsystems - Beijing China 	 */
1344dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
1345dd1de374Slin wang - Sun Microsystems - Beijing China 
1346dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!AR_SREV_5416_V20_OR_LATER(ah) ||
1347dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_SREV_9280_10_OR_LATER(ah))
1348dd1de374Slin wang - Sun Microsystems - Beijing China 		return;
1349dd1de374Slin wang - Sun Microsystems - Beijing China 
1350dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, 0x9800 + (651 << 2), 0x11);
1351dd1de374Slin wang - Sun Microsystems - Beijing China }
1352dd1de374Slin wang - Sun Microsystems - Beijing China 
1353dd1de374Slin wang - Sun Microsystems - Beijing China static uint32_t
1354dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_def_ini_fixup(struct ath_hal *ah,
1355dd1de374Slin wang - Sun Microsystems - Beijing China     struct ar5416_eeprom_def *pEepData,
1356dd1de374Slin wang - Sun Microsystems - Beijing China     uint32_t reg, uint32_t value)
1357dd1de374Slin wang - Sun Microsystems - Beijing China {
1358dd1de374Slin wang - Sun Microsystems - Beijing China 	struct base_eep_header *pBase = &(pEepData->baseEepHeader);
1359dd1de374Slin wang - Sun Microsystems - Beijing China 
1360dd1de374Slin wang - Sun Microsystems - Beijing China 	switch (ah->ah_devid) {
1361dd1de374Slin wang - Sun Microsystems - Beijing China 	case AR9280_DEVID_PCI:
1362dd1de374Slin wang - Sun Microsystems - Beijing China 		if (reg == 0x7894) {
1363dd1de374Slin wang - Sun Microsystems - Beijing China 			ARN_DBG((ARN_DBG_ANY,
1364dd1de374Slin wang - Sun Microsystems - Beijing China 			    "arn: ath9k_hw_ini_fixup(): "
1365dd1de374Slin wang - Sun Microsystems - Beijing China 			    "ini VAL: %x  EEPROM: %x\n",
1366dd1de374Slin wang - Sun Microsystems - Beijing China 			    value, (pBase->version & 0xff)));
1367dd1de374Slin wang - Sun Microsystems - Beijing China 
1368dd1de374Slin wang - Sun Microsystems - Beijing China 			if ((pBase->version & 0xff) > 0x0a) {
1369dd1de374Slin wang - Sun Microsystems - Beijing China 				ARN_DBG((ARN_DBG_ANY,
1370dd1de374Slin wang - Sun Microsystems - Beijing China 				    "arn: ath9k_hw_ini_fixup(): "
1371dd1de374Slin wang - Sun Microsystems - Beijing China 				    "PWDCLKIND: %d\n",
1372dd1de374Slin wang - Sun Microsystems - Beijing China 				    pBase->pwdclkind));
1373dd1de374Slin wang - Sun Microsystems - Beijing China 
1374dd1de374Slin wang - Sun Microsystems - Beijing China 				value &= ~AR_AN_TOP2_PWDCLKIND;
1375dd1de374Slin wang - Sun Microsystems - Beijing China 				value |= AR_AN_TOP2_PWDCLKIND &
1376dd1de374Slin wang - Sun Microsystems - Beijing China 				    (pBase->pwdclkind <<
1377dd1de374Slin wang - Sun Microsystems - Beijing China 				    AR_AN_TOP2_PWDCLKIND_S);
1378dd1de374Slin wang - Sun Microsystems - Beijing China 			} else {
1379dd1de374Slin wang - Sun Microsystems - Beijing China 				ARN_DBG((ARN_DBG_ANY,
1380dd1de374Slin wang - Sun Microsystems - Beijing China 				    "arn: ath9k_hw_ini_fixup(): "
1381dd1de374Slin wang - Sun Microsystems - Beijing China 				    "PWDCLKIND Earlier Rev\n"));
1382dd1de374Slin wang - Sun Microsystems - Beijing China 			}
1383dd1de374Slin wang - Sun Microsystems - Beijing China 
1384dd1de374Slin wang - Sun Microsystems - Beijing China 			ARN_DBG((ARN_DBG_ANY,
1385dd1de374Slin wang - Sun Microsystems - Beijing China 			    "arn: ath9k_hw_ini_fixup(): "
1386dd1de374Slin wang - Sun Microsystems - Beijing China 			    "final ini VAL: %x\n\n", value));
1387dd1de374Slin wang - Sun Microsystems - Beijing China 		}
1388dd1de374Slin wang - Sun Microsystems - Beijing China 		break;
1389dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1390dd1de374Slin wang - Sun Microsystems - Beijing China 
1391dd1de374Slin wang - Sun Microsystems - Beijing China 	return (value);
1392dd1de374Slin wang - Sun Microsystems - Beijing China }
1393dd1de374Slin wang - Sun Microsystems - Beijing China 
1394dd1de374Slin wang - Sun Microsystems - Beijing China static uint32_t
1395dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_ini_fixup(struct ath_hal *ah, struct ar5416_eeprom_def *pEepData,
1396dd1de374Slin wang - Sun Microsystems - Beijing China     uint32_t reg, uint32_t value)
1397dd1de374Slin wang - Sun Microsystems - Beijing China {
1398dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
1399dd1de374Slin wang - Sun Microsystems - Beijing China 
1400dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ahp->ah_eep_map == EEP_MAP_4KBITS)
1401dd1de374Slin wang - Sun Microsystems - Beijing China 		return (value);
1402dd1de374Slin wang - Sun Microsystems - Beijing China 	else
1403dd1de374Slin wang - Sun Microsystems - Beijing China 		return (ath9k_hw_def_ini_fixup(ah, pEepData, reg, value));
1404dd1de374Slin wang - Sun Microsystems - Beijing China }
1405dd1de374Slin wang - Sun Microsystems - Beijing China 
1406dd1de374Slin wang - Sun Microsystems - Beijing China static int
1407dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_process_ini(struct ath_hal *ah,
1408dd1de374Slin wang - Sun Microsystems - Beijing China     struct ath9k_channel *chan,
1409dd1de374Slin wang - Sun Microsystems - Beijing China     enum ath9k_ht_macmode macmode)
1410dd1de374Slin wang - Sun Microsystems - Beijing China {
1411dd1de374Slin wang - Sun Microsystems - Beijing China 	int i, regWrites = 0;
1412dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
1413dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t modesIndex, freqIndex;
1414dd1de374Slin wang - Sun Microsystems - Beijing China 	int status;
1415dd1de374Slin wang - Sun Microsystems - Beijing China 
1416dd1de374Slin wang - Sun Microsystems - Beijing China 	switch (chan->chanmode) {
1417dd1de374Slin wang - Sun Microsystems - Beijing China 	case CHANNEL_A:
1418dd1de374Slin wang - Sun Microsystems - Beijing China 	case CHANNEL_A_HT20:
1419dd1de374Slin wang - Sun Microsystems - Beijing China 		modesIndex = 1;
1420dd1de374Slin wang - Sun Microsystems - Beijing China 		freqIndex = 1;
1421dd1de374Slin wang - Sun Microsystems - Beijing China 		break;
1422dd1de374Slin wang - Sun Microsystems - Beijing China 	case CHANNEL_A_HT40PLUS:
1423dd1de374Slin wang - Sun Microsystems - Beijing China 	case CHANNEL_A_HT40MINUS:
1424dd1de374Slin wang - Sun Microsystems - Beijing China 		modesIndex = 2;
1425dd1de374Slin wang - Sun Microsystems - Beijing China 		freqIndex = 1;
1426dd1de374Slin wang - Sun Microsystems - Beijing China 		break;
1427dd1de374Slin wang - Sun Microsystems - Beijing China 	case CHANNEL_G:
1428dd1de374Slin wang - Sun Microsystems - Beijing China 	case CHANNEL_G_HT20:
1429dd1de374Slin wang - Sun Microsystems - Beijing China 	case CHANNEL_B:
1430dd1de374Slin wang - Sun Microsystems - Beijing China 		modesIndex = 4;
1431dd1de374Slin wang - Sun Microsystems - Beijing China 		freqIndex = 2;
1432dd1de374Slin wang - Sun Microsystems - Beijing China 		break;
1433dd1de374Slin wang - Sun Microsystems - Beijing China 	case CHANNEL_G_HT40PLUS:
1434dd1de374Slin wang - Sun Microsystems - Beijing China 	case CHANNEL_G_HT40MINUS:
1435dd1de374Slin wang - Sun Microsystems - Beijing China 		modesIndex = 3;
1436dd1de374Slin wang - Sun Microsystems - Beijing China 		freqIndex = 2;
1437dd1de374Slin wang - Sun Microsystems - Beijing China 		break;
1438dd1de374Slin wang - Sun Microsystems - Beijing China 
1439dd1de374Slin wang - Sun Microsystems - Beijing China 	default:
1440dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_CHANNEL, "arn: "
1441dd1de374Slin wang - Sun Microsystems - Beijing China 		    "%s: err: unknow chan->chanmode\n", __func__));
1442dd1de374Slin wang - Sun Microsystems - Beijing China 		return (EINVAL);
1443dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1444dd1de374Slin wang - Sun Microsystems - Beijing China 
1445dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY(0), 0x00000007);
1446dd1de374Slin wang - Sun Microsystems - Beijing China 
1447dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_EXTERNAL_RADIO);
1448dd1de374Slin wang - Sun Microsystems - Beijing China 
1449dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_set_addac(ah, chan);
1450dd1de374Slin wang - Sun Microsystems - Beijing China 
1451dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_5416_V22_OR_LATER(ah)) {
1452dd1de374Slin wang - Sun Microsystems - Beijing China 		/* LINTED: E_CONSTANT_CONDITION */
1453dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE_ARRAY(&ahp->ah_iniAddac, 1, regWrites);
1454dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
1455dd1de374Slin wang - Sun Microsystems - Beijing China 		struct ar5416IniArray temp;
1456dd1de374Slin wang - Sun Microsystems - Beijing China 		uint32_t addacSize =
1457dd1de374Slin wang - Sun Microsystems - Beijing China 		    sizeof (uint32_t) * ahp->ah_iniAddac.ia_rows *
1458dd1de374Slin wang - Sun Microsystems - Beijing China 		    ahp->ah_iniAddac.ia_columns;
1459dd1de374Slin wang - Sun Microsystems - Beijing China 
1460dd1de374Slin wang - Sun Microsystems - Beijing China 		(void) memcpy(ahp->ah_addac5416_21,
1461dd1de374Slin wang - Sun Microsystems - Beijing China 		    ahp->ah_iniAddac.ia_array, addacSize);
1462dd1de374Slin wang - Sun Microsystems - Beijing China 
1463dd1de374Slin wang - Sun Microsystems - Beijing China 		(ahp->ah_addac5416_21)
1464dd1de374Slin wang - Sun Microsystems - Beijing China 		    [31 * ahp->ah_iniAddac.ia_columns + 1] = 0;
1465dd1de374Slin wang - Sun Microsystems - Beijing China 
1466dd1de374Slin wang - Sun Microsystems - Beijing China 		temp.ia_array = ahp->ah_addac5416_21;
1467dd1de374Slin wang - Sun Microsystems - Beijing China 		temp.ia_columns = ahp->ah_iniAddac.ia_columns;
1468dd1de374Slin wang - Sun Microsystems - Beijing China 		temp.ia_rows = ahp->ah_iniAddac.ia_rows;
1469dd1de374Slin wang - Sun Microsystems - Beijing China 		/* LINTED: E_CONSTANT_CONDITION */
1470dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE_ARRAY(&temp, 1, regWrites);
1471dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1472dd1de374Slin wang - Sun Microsystems - Beijing China 
1473dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC);
1474dd1de374Slin wang - Sun Microsystems - Beijing China 
1475dd1de374Slin wang - Sun Microsystems - Beijing China 	for (i = 0; i < ahp->ah_iniModes.ia_rows; i++) {
1476dd1de374Slin wang - Sun Microsystems - Beijing China 		uint32_t reg = INI_RA(&ahp->ah_iniModes, i, 0);
1477dd1de374Slin wang - Sun Microsystems - Beijing China 		uint32_t val = INI_RA(&ahp->ah_iniModes, i, modesIndex);
1478dd1de374Slin wang - Sun Microsystems - Beijing China 
1479dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, reg, val);
1480dd1de374Slin wang - Sun Microsystems - Beijing China 
1481dd1de374Slin wang - Sun Microsystems - Beijing China 		if (reg >= 0x7800 && reg < 0x78a0 &&
1482dd1de374Slin wang - Sun Microsystems - Beijing China 		    ah->ah_config.analog_shiftreg) {
1483dd1de374Slin wang - Sun Microsystems - Beijing China 			drv_usecwait(100);
1484dd1de374Slin wang - Sun Microsystems - Beijing China 		}
1485dd1de374Slin wang - Sun Microsystems - Beijing China 
1486dd1de374Slin wang - Sun Microsystems - Beijing China 		/* LINTED: E_CONSTANT_CONDITION */
1487dd1de374Slin wang - Sun Microsystems - Beijing China 		DO_DELAY(regWrites);
1488dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1489dd1de374Slin wang - Sun Microsystems - Beijing China 
1490dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9280(ah)) {
1491dd1de374Slin wang - Sun Microsystems - Beijing China 		/* LINTED: E_CONSTANT_CONDITION */
1492dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE_ARRAY(&ahp->ah_iniModesRxGain, modesIndex,
1493dd1de374Slin wang - Sun Microsystems - Beijing China 		    regWrites);
1494dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1495dd1de374Slin wang - Sun Microsystems - Beijing China 
1496dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9280(ah)) {
1497dd1de374Slin wang - Sun Microsystems - Beijing China 		/* LINTED: E_CONSTANT_CONDITION */
1498dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE_ARRAY(&ahp->ah_iniModesTxGain, modesIndex,
1499dd1de374Slin wang - Sun Microsystems - Beijing China 		    regWrites);
1500dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1501dd1de374Slin wang - Sun Microsystems - Beijing China 
1502dd1de374Slin wang - Sun Microsystems - Beijing China 	for (i = 0; i < ahp->ah_iniCommon.ia_rows; i++) {
1503dd1de374Slin wang - Sun Microsystems - Beijing China 		uint32_t reg = INI_RA(&ahp->ah_iniCommon, i, 0);
1504dd1de374Slin wang - Sun Microsystems - Beijing China 		uint32_t val = INI_RA(&ahp->ah_iniCommon, i, 1);
1505dd1de374Slin wang - Sun Microsystems - Beijing China 
1506dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, reg, val);
1507dd1de374Slin wang - Sun Microsystems - Beijing China 
1508dd1de374Slin wang - Sun Microsystems - Beijing China 		if (reg >= 0x7800 && reg < 0x78a0 &&
1509dd1de374Slin wang - Sun Microsystems - Beijing China 		    ah->ah_config.analog_shiftreg) {
1510dd1de374Slin wang - Sun Microsystems - Beijing China 			drv_usecwait(100);
1511dd1de374Slin wang - Sun Microsystems - Beijing China 		}
1512dd1de374Slin wang - Sun Microsystems - Beijing China 
1513dd1de374Slin wang - Sun Microsystems - Beijing China 		/* LINTED: E_CONSTANT_CONDITION */
1514dd1de374Slin wang - Sun Microsystems - Beijing China 		DO_DELAY(regWrites);
1515dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1516dd1de374Slin wang - Sun Microsystems - Beijing China 
1517dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_write_regs(ah, modesIndex, freqIndex, regWrites);
1518dd1de374Slin wang - Sun Microsystems - Beijing China 
1519dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan)) {
1520dd1de374Slin wang - Sun Microsystems - Beijing China 		/* LINTED: E_CONSTANT_CONDITION */
1521dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE_ARRAY(&ahp->ah_iniModesAdditional, modesIndex,
1522dd1de374Slin wang - Sun Microsystems - Beijing China 		    regWrites);
1523dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1524dd1de374Slin wang - Sun Microsystems - Beijing China 
1525dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_override_ini(ah, chan);
1526dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_set_regs(ah, chan, macmode);
1527dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_init_chain_masks(ah);
1528dd1de374Slin wang - Sun Microsystems - Beijing China 
1529dd1de374Slin wang - Sun Microsystems - Beijing China 	status = ath9k_hw_set_txpower(ah, chan,
1530dd1de374Slin wang - Sun Microsystems - Beijing China 	    ath9k_regd_get_ctl(ah, chan),
1531dd1de374Slin wang - Sun Microsystems - Beijing China 	    ath9k_regd_get_antenna_allowed(ah, chan),
1532dd1de374Slin wang - Sun Microsystems - Beijing China 	    chan->maxRegTxPower * 2,
1533dd1de374Slin wang - Sun Microsystems - Beijing China 	    min((uint32_t)MAX_RATE_POWER,
1534dd1de374Slin wang - Sun Microsystems - Beijing China 	    (uint32_t)ah->ah_powerLimit));
1535dd1de374Slin wang - Sun Microsystems - Beijing China 	if (status != 0) {
1536dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_ANY, "arn: ath9k_hw_process_ini(): "
1537dd1de374Slin wang - Sun Microsystems - Beijing China 		    "%s: error init'ing transmit power\n", __func__));
1538dd1de374Slin wang - Sun Microsystems - Beijing China 
1539dd1de374Slin wang - Sun Microsystems - Beijing China 		return (EIO);
1540dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1541dd1de374Slin wang - Sun Microsystems - Beijing China 
1542dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
1543dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_ANY, "arn: ath9k_hw_process_ini(): "
1544dd1de374Slin wang - Sun Microsystems - Beijing China 		    "%s: ar5416SetRfRegs failed\n", __func__));
1545dd1de374Slin wang - Sun Microsystems - Beijing China 
1546dd1de374Slin wang - Sun Microsystems - Beijing China 		return (EIO);
1547dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1548dd1de374Slin wang - Sun Microsystems - Beijing China 
1549dd1de374Slin wang - Sun Microsystems - Beijing China 	return (0);
1550dd1de374Slin wang - Sun Microsystems - Beijing China }
1551dd1de374Slin wang - Sun Microsystems - Beijing China 
1552dd1de374Slin wang - Sun Microsystems - Beijing China /* Reset and Channel Switching Routines */
1553dd1de374Slin wang - Sun Microsystems - Beijing China 
1554dd1de374Slin wang - Sun Microsystems - Beijing China static void
1555dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_set_rfmode(struct ath_hal *ah, struct ath9k_channel *chan)
1556dd1de374Slin wang - Sun Microsystems - Beijing China {
1557dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t rfMode = 0;
1558dd1de374Slin wang - Sun Microsystems - Beijing China 
1559dd1de374Slin wang - Sun Microsystems - Beijing China 	if (chan == NULL)
1560dd1de374Slin wang - Sun Microsystems - Beijing China 		return;
1561dd1de374Slin wang - Sun Microsystems - Beijing China 
1562dd1de374Slin wang - Sun Microsystems - Beijing China 	rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
1563dd1de374Slin wang - Sun Microsystems - Beijing China 	    ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
1564dd1de374Slin wang - Sun Microsystems - Beijing China 
1565dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!AR_SREV_9280_10_OR_LATER(ah))
1566dd1de374Slin wang - Sun Microsystems - Beijing China 		rfMode |= (IS_CHAN_5GHZ(chan)) ?
1567dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_PHY_MODE_RF5GHZ : AR_PHY_MODE_RF2GHZ;
1568dd1de374Slin wang - Sun Microsystems - Beijing China 
1569dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan))
1570dd1de374Slin wang - Sun Microsystems - Beijing China 		rfMode |= (AR_PHY_MODE_DYNAMIC |
1571dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_PHY_MODE_DYN_CCK_DISABLE);
1572dd1de374Slin wang - Sun Microsystems - Beijing China 
1573dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_MODE, rfMode);
1574dd1de374Slin wang - Sun Microsystems - Beijing China }
1575dd1de374Slin wang - Sun Microsystems - Beijing China 
1576dd1de374Slin wang - Sun Microsystems - Beijing China static void
1577dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_mark_phy_inactive(struct ath_hal *ah)
1578dd1de374Slin wang - Sun Microsystems - Beijing China {
1579dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
1580dd1de374Slin wang - Sun Microsystems - Beijing China }
1581dd1de374Slin wang - Sun Microsystems - Beijing China 
1582dd1de374Slin wang - Sun Microsystems - Beijing China static inline void
1583dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_set_dma(struct ath_hal *ah)
1584dd1de374Slin wang - Sun Microsystems - Beijing China {
1585dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t regval;
1586dd1de374Slin wang - Sun Microsystems - Beijing China 
1587dd1de374Slin wang - Sun Microsystems - Beijing China 	regval = REG_READ(ah, AR_AHB_MODE);
1588dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
1589dd1de374Slin wang - Sun Microsystems - Beijing China 
1590dd1de374Slin wang - Sun Microsystems - Beijing China 	regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
1591dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
1592dd1de374Slin wang - Sun Microsystems - Beijing China 
1593dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->ah_txTrigLevel);
1594dd1de374Slin wang - Sun Microsystems - Beijing China 
1595dd1de374Slin wang - Sun Microsystems - Beijing China 	regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
1596dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
1597dd1de374Slin wang - Sun Microsystems - Beijing China 
1598dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1599dd1de374Slin wang - Sun Microsystems - Beijing China 
1600dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9285(ah)) {
1601dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1602dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
1603dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
1604dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1605dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_PCU_TXBUF_CTRL_USABLE_SIZE);
1606dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1607dd1de374Slin wang - Sun Microsystems - Beijing China }
1608dd1de374Slin wang - Sun Microsystems - Beijing China 
1609dd1de374Slin wang - Sun Microsystems - Beijing China static void
1610dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_set_operating_mode(struct ath_hal *ah, int opmode)
1611dd1de374Slin wang - Sun Microsystems - Beijing China {
1612dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t val;
1613dd1de374Slin wang - Sun Microsystems - Beijing China 
1614dd1de374Slin wang - Sun Microsystems - Beijing China 	val = REG_READ(ah, AR_STA_ID1);
1615dd1de374Slin wang - Sun Microsystems - Beijing China 	val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
1616dd1de374Slin wang - Sun Microsystems - Beijing China 	switch (opmode) {
1617dd1de374Slin wang - Sun Microsystems - Beijing China 	case ATH9K_M_HOSTAP:
1618dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP |
1619dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_STA_ID1_KSRCH_MODE);
1620dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1621dd1de374Slin wang - Sun Microsystems - Beijing China 		break;
1622dd1de374Slin wang - Sun Microsystems - Beijing China 	case ATH9K_M_IBSS:
1623dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC |
1624dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_STA_ID1_KSRCH_MODE);
1625dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1626dd1de374Slin wang - Sun Microsystems - Beijing China 		break;
1627dd1de374Slin wang - Sun Microsystems - Beijing China 	case ATH9K_M_STA:
1628dd1de374Slin wang - Sun Microsystems - Beijing China 	case ATH9K_M_MONITOR:
1629dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
1630dd1de374Slin wang - Sun Microsystems - Beijing China 		break;
1631dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1632dd1de374Slin wang - Sun Microsystems - Beijing China }
1633dd1de374Slin wang - Sun Microsystems - Beijing China 
1634dd1de374Slin wang - Sun Microsystems - Beijing China /* ARGSUSED */
1635dd1de374Slin wang - Sun Microsystems - Beijing China static inline void
1636dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_get_delta_slope_vals(struct ath_hal *ah,
1637dd1de374Slin wang - Sun Microsystems - Beijing China     uint32_t coef_scaled,
1638dd1de374Slin wang - Sun Microsystems - Beijing China     uint32_t *coef_mantissa,
1639dd1de374Slin wang - Sun Microsystems - Beijing China     uint32_t *coef_exponent)
1640dd1de374Slin wang - Sun Microsystems - Beijing China {
1641dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t coef_exp, coef_man;
1642dd1de374Slin wang - Sun Microsystems - Beijing China 
1643dd1de374Slin wang - Sun Microsystems - Beijing China 	for (coef_exp = 31; coef_exp > 0; coef_exp--)
1644dd1de374Slin wang - Sun Microsystems - Beijing China 		if ((coef_scaled >> coef_exp) & 0x1)
1645dd1de374Slin wang - Sun Microsystems - Beijing China 			break;
1646dd1de374Slin wang - Sun Microsystems - Beijing China 
1647dd1de374Slin wang - Sun Microsystems - Beijing China 	coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1648dd1de374Slin wang - Sun Microsystems - Beijing China 
1649dd1de374Slin wang - Sun Microsystems - Beijing China 	coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1650dd1de374Slin wang - Sun Microsystems - Beijing China 
1651dd1de374Slin wang - Sun Microsystems - Beijing China 	*coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1652dd1de374Slin wang - Sun Microsystems - Beijing China 	*coef_exponent = coef_exp - 16;
1653dd1de374Slin wang - Sun Microsystems - Beijing China }
1654dd1de374Slin wang - Sun Microsystems - Beijing China 
1655dd1de374Slin wang - Sun Microsystems - Beijing China static void
1656dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_set_delta_slope(struct ath_hal *ah,
1657dd1de374Slin wang - Sun Microsystems - Beijing China     struct ath9k_channel *chan)
1658dd1de374Slin wang - Sun Microsystems - Beijing China {
1659dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t coef_scaled, ds_coef_exp, ds_coef_man;
1660dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t clockMhzScaled = 0x64000000;
1661dd1de374Slin wang - Sun Microsystems - Beijing China 	struct chan_centers centers;
1662dd1de374Slin wang - Sun Microsystems - Beijing China 
1663dd1de374Slin wang - Sun Microsystems - Beijing China 	if (IS_CHAN_HALF_RATE(chan))
1664dd1de374Slin wang - Sun Microsystems - Beijing China 		clockMhzScaled = clockMhzScaled >> 1;
1665dd1de374Slin wang - Sun Microsystems - Beijing China 	else if (IS_CHAN_QUARTER_RATE(chan))
1666dd1de374Slin wang - Sun Microsystems - Beijing China 		clockMhzScaled = clockMhzScaled >> 2;
1667dd1de374Slin wang - Sun Microsystems - Beijing China 
1668dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_get_channel_centers(ah, chan, &centers);
1669dd1de374Slin wang - Sun Microsystems - Beijing China 	coef_scaled = clockMhzScaled / centers.synth_center;
1670dd1de374Slin wang - Sun Microsystems - Beijing China 
1671dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1672dd1de374Slin wang - Sun Microsystems - Beijing China 	    &ds_coef_exp);
1673dd1de374Slin wang - Sun Microsystems - Beijing China 
1674dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1675dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
1676dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1677dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
1678dd1de374Slin wang - Sun Microsystems - Beijing China 
1679dd1de374Slin wang - Sun Microsystems - Beijing China 	coef_scaled = (9 * coef_scaled) / 10;
1680dd1de374Slin wang - Sun Microsystems - Beijing China 
1681dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1682dd1de374Slin wang - Sun Microsystems - Beijing China 	    &ds_coef_exp);
1683dd1de374Slin wang - Sun Microsystems - Beijing China 
1684dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1685dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_PHY_HALFGI_DSC_MAN, ds_coef_man);
1686dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1687dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_PHY_HALFGI_DSC_EXP, ds_coef_exp);
1688dd1de374Slin wang - Sun Microsystems - Beijing China }
1689dd1de374Slin wang - Sun Microsystems - Beijing China 
1690dd1de374Slin wang - Sun Microsystems - Beijing China static boolean_t
1691dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_set_reset(struct ath_hal *ah, int type)
1692dd1de374Slin wang - Sun Microsystems - Beijing China {
1693dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t rst_flags;
1694dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t tmpReg;
1695dd1de374Slin wang - Sun Microsystems - Beijing China 
1696dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1697dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_RTC_FORCE_WAKE_ON_INT);
1698dd1de374Slin wang - Sun Microsystems - Beijing China 
1699dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9100(ah)) {
1700dd1de374Slin wang - Sun Microsystems - Beijing China 		rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1701dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1702dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
1703dd1de374Slin wang - Sun Microsystems - Beijing China 		tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1704dd1de374Slin wang - Sun Microsystems - Beijing China 		if (tmpReg &
1705dd1de374Slin wang - Sun Microsystems - Beijing China 		    (AR_INTR_SYNC_LOCAL_TIMEOUT |
1706dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
1707dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
1708dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
1709dd1de374Slin wang - Sun Microsystems - Beijing China 		} else {
1710dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_WRITE(ah, AR_RC, AR_RC_AHB);
1711dd1de374Slin wang - Sun Microsystems - Beijing China 		}
1712dd1de374Slin wang - Sun Microsystems - Beijing China 
1713dd1de374Slin wang - Sun Microsystems - Beijing China 		rst_flags = AR_RTC_RC_MAC_WARM;
1714dd1de374Slin wang - Sun Microsystems - Beijing China 		if (type == ATH9K_RESET_COLD)
1715dd1de374Slin wang - Sun Microsystems - Beijing China 			rst_flags |= AR_RTC_RC_MAC_COLD;
1716dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1717dd1de374Slin wang - Sun Microsystems - Beijing China 
1718dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, (uint16_t)(AR_RTC_RC), rst_flags);
1719dd1de374Slin wang - Sun Microsystems - Beijing China 	drv_usecwait(50);
1720dd1de374Slin wang - Sun Microsystems - Beijing China 
1721dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, (uint16_t)(AR_RTC_RC), 0);
1722dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!ath9k_hw_wait(ah, (uint16_t)(AR_RTC_RC), AR_RTC_RC_M, 0)) {
1723dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_HW, "arn: ath9k_hw_set_reset(): "
1724dd1de374Slin wang - Sun Microsystems - Beijing China 		    "RTC stuck in MAC reset\n"));
1725dd1de374Slin wang - Sun Microsystems - Beijing China 
1726dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_FALSE);
1727dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1728dd1de374Slin wang - Sun Microsystems - Beijing China 
1729dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!AR_SREV_9100(ah))
1730dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_RC, 0);
1731dd1de374Slin wang - Sun Microsystems - Beijing China 
1732dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_init_pll(ah, NULL);
1733dd1de374Slin wang - Sun Microsystems - Beijing China 
1734dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9100(ah))
1735dd1de374Slin wang - Sun Microsystems - Beijing China 		drv_usecwait(50);
1736dd1de374Slin wang - Sun Microsystems - Beijing China 
1737dd1de374Slin wang - Sun Microsystems - Beijing China 	return (B_TRUE);
1738dd1de374Slin wang - Sun Microsystems - Beijing China }
1739dd1de374Slin wang - Sun Microsystems - Beijing China 
1740dd1de374Slin wang - Sun Microsystems - Beijing China static boolean_t
1741dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_set_reset_power_on(struct ath_hal *ah)
1742dd1de374Slin wang - Sun Microsystems - Beijing China {
1743dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1744dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_RTC_FORCE_WAKE_ON_INT);
1745dd1de374Slin wang - Sun Microsystems - Beijing China 
1746dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, (uint16_t)(AR_RTC_RESET), 0);
1747dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, (uint16_t)(AR_RTC_RESET), 1);
1748dd1de374Slin wang - Sun Microsystems - Beijing China 
1749dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!ath9k_hw_wait(ah,
1750dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_RTC_STATUS,
1751dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_RTC_STATUS_M,
1752dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_RTC_STATUS_ON)) {
1753dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_HW,
1754dd1de374Slin wang - Sun Microsystems - Beijing China 		    "arn: ath9k_hw_set_reset_power_on(): "
1755dd1de374Slin wang - Sun Microsystems - Beijing China 		    "RTC not waking up \n"));
1756dd1de374Slin wang - Sun Microsystems - Beijing China 
1757dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_FALSE);
1758dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1759dd1de374Slin wang - Sun Microsystems - Beijing China 
1760dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_read_revisions(ah);
1761dd1de374Slin wang - Sun Microsystems - Beijing China 
1762dd1de374Slin wang - Sun Microsystems - Beijing China 	return (ath9k_hw_set_reset(ah, ATH9K_RESET_WARM));
1763dd1de374Slin wang - Sun Microsystems - Beijing China }
1764dd1de374Slin wang - Sun Microsystems - Beijing China 
1765dd1de374Slin wang - Sun Microsystems - Beijing China static boolean_t
1766dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_set_reset_reg(struct ath_hal *ah, uint32_t type)
1767dd1de374Slin wang - Sun Microsystems - Beijing China {
1768dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1769dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1770dd1de374Slin wang - Sun Microsystems - Beijing China 
1771dd1de374Slin wang - Sun Microsystems - Beijing China 	switch (type) {
1772dd1de374Slin wang - Sun Microsystems - Beijing China 	case ATH9K_RESET_POWER_ON:
1773dd1de374Slin wang - Sun Microsystems - Beijing China 		return (ath9k_hw_set_reset_power_on(ah));
1774dd1de374Slin wang - Sun Microsystems - Beijing China 	case ATH9K_RESET_WARM:
1775dd1de374Slin wang - Sun Microsystems - Beijing China 	case ATH9K_RESET_COLD:
1776dd1de374Slin wang - Sun Microsystems - Beijing China 		return (ath9k_hw_set_reset(ah, type));
1777dd1de374Slin wang - Sun Microsystems - Beijing China 	default:
1778dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_FALSE);
1779dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1780dd1de374Slin wang - Sun Microsystems - Beijing China }
1781dd1de374Slin wang - Sun Microsystems - Beijing China 
1782dd1de374Slin wang - Sun Microsystems - Beijing China static void
1783dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_set_regs(struct ath_hal *ah, struct ath9k_channel *chan,
1784dd1de374Slin wang - Sun Microsystems - Beijing China     enum ath9k_ht_macmode macmode)
1785dd1de374Slin wang - Sun Microsystems - Beijing China {
1786dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t phymode;
1787dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t enableDacFifo = 0;
1788dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
1789dd1de374Slin wang - Sun Microsystems - Beijing China 
1790dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9285_10_OR_LATER(ah))
1791dd1de374Slin wang - Sun Microsystems - Beijing China 		enableDacFifo = (REG_READ(ah, AR_PHY_TURBO) &
1792dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_PHY_FC_ENABLE_DAC_FIFO);
1793dd1de374Slin wang - Sun Microsystems - Beijing China 
1794dd1de374Slin wang - Sun Microsystems - Beijing China 	phymode = AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40 |
1795dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH | enableDacFifo;
1796dd1de374Slin wang - Sun Microsystems - Beijing China 
1797dd1de374Slin wang - Sun Microsystems - Beijing China 	if (IS_CHAN_HT40(chan)) {
1798dd1de374Slin wang - Sun Microsystems - Beijing China 		phymode |= AR_PHY_FC_DYN2040_EN;
1799dd1de374Slin wang - Sun Microsystems - Beijing China 
1800dd1de374Slin wang - Sun Microsystems - Beijing China 		if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
1801dd1de374Slin wang - Sun Microsystems - Beijing China 		    (chan->chanmode == CHANNEL_G_HT40PLUS))
1802dd1de374Slin wang - Sun Microsystems - Beijing China 			phymode |= AR_PHY_FC_DYN2040_PRI_CH;
1803dd1de374Slin wang - Sun Microsystems - Beijing China 
1804dd1de374Slin wang - Sun Microsystems - Beijing China 		if (ahp->ah_extprotspacing == ATH9K_HT_EXTPROTSPACING_25)
1805dd1de374Slin wang - Sun Microsystems - Beijing China 			phymode |= AR_PHY_FC_DYN2040_EXT_CH;
1806dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1807dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_TURBO, phymode);
1808dd1de374Slin wang - Sun Microsystems - Beijing China 
1809dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_set11nmac2040(ah, macmode);
1810dd1de374Slin wang - Sun Microsystems - Beijing China 
1811dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
1812dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
1813dd1de374Slin wang - Sun Microsystems - Beijing China }
1814dd1de374Slin wang - Sun Microsystems - Beijing China 
1815dd1de374Slin wang - Sun Microsystems - Beijing China static boolean_t
1816dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_chip_reset(struct ath_hal *ah,
1817dd1de374Slin wang - Sun Microsystems - Beijing China     struct ath9k_channel *chan)
1818dd1de374Slin wang - Sun Microsystems - Beijing China {
1819dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
1820dd1de374Slin wang - Sun Microsystems - Beijing China 
1821dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
1822dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_FALSE);
1823dd1de374Slin wang - Sun Microsystems - Beijing China 
1824dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
1825dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_FALSE);
1826dd1de374Slin wang - Sun Microsystems - Beijing China 
1827dd1de374Slin wang - Sun Microsystems - Beijing China 	ahp->ah_chipFullSleep = B_FALSE;
1828dd1de374Slin wang - Sun Microsystems - Beijing China 
1829dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_init_pll(ah, chan);
1830dd1de374Slin wang - Sun Microsystems - Beijing China 
1831dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_set_rfmode(ah, chan);
1832dd1de374Slin wang - Sun Microsystems - Beijing China 
1833dd1de374Slin wang - Sun Microsystems - Beijing China 	return (B_TRUE);
1834dd1de374Slin wang - Sun Microsystems - Beijing China }
1835dd1de374Slin wang - Sun Microsystems - Beijing China 
1836dd1de374Slin wang - Sun Microsystems - Beijing China static struct ath9k_channel *
1837dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_check_chan(struct ath_hal *ah, struct ath9k_channel *chan)
1838dd1de374Slin wang - Sun Microsystems - Beijing China {
1839dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!(IS_CHAN_2GHZ(chan) ^ IS_CHAN_5GHZ(chan))) {
1840dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_CHANNEL, "arn: "
1841dd1de374Slin wang - Sun Microsystems - Beijing China 		    "%s: invalid channel %u/0x%x; not marked as "
1842dd1de374Slin wang - Sun Microsystems - Beijing China 		    "2GHz or 5GHz\n",
1843dd1de374Slin wang - Sun Microsystems - Beijing China 		    __func__, chan->channel, chan->channelFlags));
1844dd1de374Slin wang - Sun Microsystems - Beijing China 		return (NULL);
1845dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1846dd1de374Slin wang - Sun Microsystems - Beijing China 
1847dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!IS_CHAN_OFDM(chan) &&
1848dd1de374Slin wang - Sun Microsystems - Beijing China 	    !IS_CHAN_B(chan) &&
1849dd1de374Slin wang - Sun Microsystems - Beijing China 	    !IS_CHAN_HT20(chan) &&
1850dd1de374Slin wang - Sun Microsystems - Beijing China 	    !IS_CHAN_HT40(chan)) {
1851dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_CHANNEL, "arn: "
1852dd1de374Slin wang - Sun Microsystems - Beijing China 		    "%s: invalid channel %u/0x%x; not marked as "
1853dd1de374Slin wang - Sun Microsystems - Beijing China 		    "OFDM or CCK or HT20 or HT40PLUS or HT40MINUS\n",
1854dd1de374Slin wang - Sun Microsystems - Beijing China 		    __func__, chan->channel, chan->channelFlags));
1855dd1de374Slin wang - Sun Microsystems - Beijing China 
1856dd1de374Slin wang - Sun Microsystems - Beijing China 		return (NULL);
1857dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1858dd1de374Slin wang - Sun Microsystems - Beijing China 	return (ath9k_regd_check_channel(ah, chan));
1859dd1de374Slin wang - Sun Microsystems - Beijing China }
1860dd1de374Slin wang - Sun Microsystems - Beijing China 
1861dd1de374Slin wang - Sun Microsystems - Beijing China static boolean_t
1862dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_channel_change(struct ath_hal *ah,
1863dd1de374Slin wang - Sun Microsystems - Beijing China     struct ath9k_channel *chan,
1864dd1de374Slin wang - Sun Microsystems - Beijing China     enum ath9k_ht_macmode macmode)
1865dd1de374Slin wang - Sun Microsystems - Beijing China {
1866dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t synthDelay, qnum;
1867dd1de374Slin wang - Sun Microsystems - Beijing China 
1868dd1de374Slin wang - Sun Microsystems - Beijing China 	for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1869dd1de374Slin wang - Sun Microsystems - Beijing China 		if (ath9k_hw_numtxpending(ah, qnum)) {
1870dd1de374Slin wang - Sun Microsystems - Beijing China 			ARN_DBG((ARN_DBG_QUEUE, "arn: "
1871dd1de374Slin wang - Sun Microsystems - Beijing China 			    "%s: Transmit frames pending on queue %d\n",
1872dd1de374Slin wang - Sun Microsystems - Beijing China 			    __func__, qnum));
1873dd1de374Slin wang - Sun Microsystems - Beijing China 
1874dd1de374Slin wang - Sun Microsystems - Beijing China 			return (B_FALSE);
1875dd1de374Slin wang - Sun Microsystems - Beijing China 		}
1876dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1877dd1de374Slin wang - Sun Microsystems - Beijing China 
1878dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
1879dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
1880dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_PHY_RFBUS_GRANT_EN)) {
1881dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_HW, "arn: "
1882dd1de374Slin wang - Sun Microsystems - Beijing China 		    "%s: Could not kill baseband RX\n", __func__));
1883dd1de374Slin wang - Sun Microsystems - Beijing China 
1884dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_FALSE);
1885dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1886dd1de374Slin wang - Sun Microsystems - Beijing China 
1887dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_set_regs(ah, chan, macmode);
1888dd1de374Slin wang - Sun Microsystems - Beijing China 
1889dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9280_10_OR_LATER(ah)) {
1890dd1de374Slin wang - Sun Microsystems - Beijing China 		if (!(ath9k_hw_ar9280_set_channel(ah, chan))) {
1891dd1de374Slin wang - Sun Microsystems - Beijing China 			ARN_DBG((ARN_DBG_CHANNEL, "arn: "
1892dd1de374Slin wang - Sun Microsystems - Beijing China 			    "%s: failed to set channel\n", __func__));
1893dd1de374Slin wang - Sun Microsystems - Beijing China 			return (B_FALSE);
1894dd1de374Slin wang - Sun Microsystems - Beijing China 		}
1895dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
1896dd1de374Slin wang - Sun Microsystems - Beijing China 		if (!(ath9k_hw_set_channel(ah, chan))) {
1897dd1de374Slin wang - Sun Microsystems - Beijing China 			ARN_DBG((ARN_DBG_CHANNEL, "arn: "
1898dd1de374Slin wang - Sun Microsystems - Beijing China 			    "%s: failed to set channel\n", __func__));
1899dd1de374Slin wang - Sun Microsystems - Beijing China 
1900dd1de374Slin wang - Sun Microsystems - Beijing China 			return (B_FALSE);
1901dd1de374Slin wang - Sun Microsystems - Beijing China 		}
1902dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1903dd1de374Slin wang - Sun Microsystems - Beijing China 
1904dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ath9k_hw_set_txpower(ah, chan,
1905dd1de374Slin wang - Sun Microsystems - Beijing China 	    ath9k_regd_get_ctl(ah, chan),
1906dd1de374Slin wang - Sun Microsystems - Beijing China 	    ath9k_regd_get_antenna_allowed(ah, chan),
1907dd1de374Slin wang - Sun Microsystems - Beijing China 	    chan->maxRegTxPower * 2,
1908dd1de374Slin wang - Sun Microsystems - Beijing China 	    min((uint32_t)MAX_RATE_POWER,
1909dd1de374Slin wang - Sun Microsystems - Beijing China 	    (uint32_t)ah->ah_powerLimit)) != 0) {
1910dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_EEPROM, "arn: "
1911dd1de374Slin wang - Sun Microsystems - Beijing China 		    "%s: error init'ing transmit power\n", __func__));
1912dd1de374Slin wang - Sun Microsystems - Beijing China 
1913dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_FALSE);
1914dd1de374Slin wang - Sun Microsystems - Beijing China 	}
1915dd1de374Slin wang - Sun Microsystems - Beijing China 
1916dd1de374Slin wang - Sun Microsystems - Beijing China 	synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
1917dd1de374Slin wang - Sun Microsystems - Beijing China 	if (IS_CHAN_B(chan))
1918dd1de374Slin wang - Sun Microsystems - Beijing China 		synthDelay = (4 * synthDelay) / 22;
1919dd1de374Slin wang - Sun Microsystems - Beijing China 	else
1920dd1de374Slin wang - Sun Microsystems - Beijing China 		synthDelay /= 10;
1921dd1de374Slin wang - Sun Microsystems - Beijing China 
1922dd1de374Slin wang - Sun Microsystems - Beijing China 	drv_usecwait(synthDelay + BASE_ACTIVATE_DELAY);
1923dd1de374Slin wang - Sun Microsystems - Beijing China 
1924dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
1925dd1de374Slin wang - Sun Microsystems - Beijing China 
1926dd1de374Slin wang - Sun Microsystems - Beijing China 	if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1927dd1de374Slin wang - Sun Microsystems - Beijing China 		ath9k_hw_set_delta_slope(ah, chan);
1928dd1de374Slin wang - Sun Microsystems - Beijing China 
1929dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9280_10_OR_LATER(ah))
1930dd1de374Slin wang - Sun Microsystems - Beijing China 		ath9k_hw_9280_spur_mitigate(ah, chan);
1931dd1de374Slin wang - Sun Microsystems - Beijing China 	else
1932dd1de374Slin wang - Sun Microsystems - Beijing China 		ath9k_hw_spur_mitigate(ah, chan);
1933dd1de374Slin wang - Sun Microsystems - Beijing China 
1934dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!chan->oneTimeCalsDone)
1935dd1de374Slin wang - Sun Microsystems - Beijing China 		chan->oneTimeCalsDone = B_TRUE;
1936dd1de374Slin wang - Sun Microsystems - Beijing China 
1937dd1de374Slin wang - Sun Microsystems - Beijing China 	return (B_TRUE);
1938dd1de374Slin wang - Sun Microsystems - Beijing China }
1939dd1de374Slin wang - Sun Microsystems - Beijing China 
1940dd1de374Slin wang - Sun Microsystems - Beijing China static void
1941dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_9280_spur_mitigate(struct ath_hal *ah, struct ath9k_channel *chan)
1942dd1de374Slin wang - Sun Microsystems - Beijing China {
1943dd1de374Slin wang - Sun Microsystems - Beijing China 	int bb_spur = AR_NO_SPUR;
1944dd1de374Slin wang - Sun Microsystems - Beijing China 	int freq;
1945dd1de374Slin wang - Sun Microsystems - Beijing China 	int bin, cur_bin;
1946dd1de374Slin wang - Sun Microsystems - Beijing China 	int bb_spur_off, spur_subchannel_sd;
1947dd1de374Slin wang - Sun Microsystems - Beijing China 	int spur_freq_sd;
1948dd1de374Slin wang - Sun Microsystems - Beijing China 	int spur_delta_phase;
1949dd1de374Slin wang - Sun Microsystems - Beijing China 	int denominator;
1950dd1de374Slin wang - Sun Microsystems - Beijing China 	int upper, lower, cur_vit_mask;
1951dd1de374Slin wang - Sun Microsystems - Beijing China 	int tmp, newVal;
1952dd1de374Slin wang - Sun Microsystems - Beijing China 	int i;
1953dd1de374Slin wang - Sun Microsystems - Beijing China 	int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
1954dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
1955dd1de374Slin wang - Sun Microsystems - Beijing China 	};
1956dd1de374Slin wang - Sun Microsystems - Beijing China 	int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
1957dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
1958dd1de374Slin wang - Sun Microsystems - Beijing China 	};
1959dd1de374Slin wang - Sun Microsystems - Beijing China 	int inc[4] = { 0, 100, 0, 0 };
1960dd1de374Slin wang - Sun Microsystems - Beijing China 	struct chan_centers centers;
1961dd1de374Slin wang - Sun Microsystems - Beijing China 
1962dd1de374Slin wang - Sun Microsystems - Beijing China 	int8_t mask_m[123];
1963dd1de374Slin wang - Sun Microsystems - Beijing China 	int8_t mask_p[123];
1964dd1de374Slin wang - Sun Microsystems - Beijing China 	int8_t mask_amt;
1965dd1de374Slin wang - Sun Microsystems - Beijing China 	int tmp_mask;
1966dd1de374Slin wang - Sun Microsystems - Beijing China 	int cur_bb_spur;
1967dd1de374Slin wang - Sun Microsystems - Beijing China 	boolean_t is2GHz = IS_CHAN_2GHZ(chan);
1968dd1de374Slin wang - Sun Microsystems - Beijing China 
1969dd1de374Slin wang - Sun Microsystems - Beijing China 	(void) memset(&mask_m, 0, sizeof (int8_t) * 123);
1970dd1de374Slin wang - Sun Microsystems - Beijing China 	(void) memset(&mask_p, 0, sizeof (int8_t) * 123);
1971dd1de374Slin wang - Sun Microsystems - Beijing China 
1972dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_get_channel_centers(ah, chan, &centers);
1973dd1de374Slin wang - Sun Microsystems - Beijing China 	freq = centers.synth_center;
1974dd1de374Slin wang - Sun Microsystems - Beijing China 
1975dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_config.spurmode = SPUR_ENABLE_EEPROM;
1976dd1de374Slin wang - Sun Microsystems - Beijing China 	for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
1977dd1de374Slin wang - Sun Microsystems - Beijing China 		cur_bb_spur = ath9k_hw_eeprom_get_spur_chan(ah, i, is2GHz);
1978dd1de374Slin wang - Sun Microsystems - Beijing China 
1979dd1de374Slin wang - Sun Microsystems - Beijing China 		if (is2GHz)
1980dd1de374Slin wang - Sun Microsystems - Beijing China 			cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_2GHZ;
1981dd1de374Slin wang - Sun Microsystems - Beijing China 		else
1982dd1de374Slin wang - Sun Microsystems - Beijing China 			cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_5GHZ;
1983dd1de374Slin wang - Sun Microsystems - Beijing China 
1984dd1de374Slin wang - Sun Microsystems - Beijing China 		if (AR_NO_SPUR == cur_bb_spur)
1985dd1de374Slin wang - Sun Microsystems - Beijing China 			break;
1986dd1de374Slin wang - Sun Microsystems - Beijing China 		cur_bb_spur = cur_bb_spur - freq;
1987dd1de374Slin wang - Sun Microsystems - Beijing China 
1988dd1de374Slin wang - Sun Microsystems - Beijing China 		if (IS_CHAN_HT40(chan)) {
1989dd1de374Slin wang - Sun Microsystems - Beijing China 			if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT40) &&
1990dd1de374Slin wang - Sun Microsystems - Beijing China 			    (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT40)) {
1991dd1de374Slin wang - Sun Microsystems - Beijing China 				bb_spur = cur_bb_spur;
1992dd1de374Slin wang - Sun Microsystems - Beijing China 				break;
1993dd1de374Slin wang - Sun Microsystems - Beijing China 			}
1994dd1de374Slin wang - Sun Microsystems - Beijing China 		} else if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT20) &&
1995dd1de374Slin wang - Sun Microsystems - Beijing China 		    (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT20)) {
1996dd1de374Slin wang - Sun Microsystems - Beijing China 			bb_spur = cur_bb_spur;
1997dd1de374Slin wang - Sun Microsystems - Beijing China 			break;
1998dd1de374Slin wang - Sun Microsystems - Beijing China 		}
1999dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2000dd1de374Slin wang - Sun Microsystems - Beijing China 
2001dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_NO_SPUR == bb_spur) {
2002dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
2003dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
2004dd1de374Slin wang - Sun Microsystems - Beijing China 		return;
2005dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
2006dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
2007dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
2008dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2009dd1de374Slin wang - Sun Microsystems - Beijing China 
2010dd1de374Slin wang - Sun Microsystems - Beijing China 	bin = bb_spur * 320;
2011dd1de374Slin wang - Sun Microsystems - Beijing China 
2012dd1de374Slin wang - Sun Microsystems - Beijing China 	tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
2013dd1de374Slin wang - Sun Microsystems - Beijing China 
2014dd1de374Slin wang - Sun Microsystems - Beijing China 	newVal = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
2015dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
2016dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
2017dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
2018dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), newVal);
2019dd1de374Slin wang - Sun Microsystems - Beijing China 
2020dd1de374Slin wang - Sun Microsystems - Beijing China 	newVal = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
2021dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
2022dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_PHY_SPUR_REG_MASK_RATE_SELECT |
2023dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
2024dd1de374Slin wang - Sun Microsystems - Beijing China 	    SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
2025dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_SPUR_REG, newVal);
2026dd1de374Slin wang - Sun Microsystems - Beijing China 
2027dd1de374Slin wang - Sun Microsystems - Beijing China 	if (IS_CHAN_HT40(chan)) {
2028dd1de374Slin wang - Sun Microsystems - Beijing China 		if (bb_spur < 0) {
2029dd1de374Slin wang - Sun Microsystems - Beijing China 			spur_subchannel_sd = 1;
2030dd1de374Slin wang - Sun Microsystems - Beijing China 			bb_spur_off = bb_spur + 10;
2031dd1de374Slin wang - Sun Microsystems - Beijing China 		} else {
2032dd1de374Slin wang - Sun Microsystems - Beijing China 			spur_subchannel_sd = 0;
2033dd1de374Slin wang - Sun Microsystems - Beijing China 			bb_spur_off = bb_spur - 10;
2034dd1de374Slin wang - Sun Microsystems - Beijing China 		}
2035dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
2036dd1de374Slin wang - Sun Microsystems - Beijing China 		spur_subchannel_sd = 0;
2037dd1de374Slin wang - Sun Microsystems - Beijing China 		bb_spur_off = bb_spur;
2038dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2039dd1de374Slin wang - Sun Microsystems - Beijing China 
2040dd1de374Slin wang - Sun Microsystems - Beijing China 	if (IS_CHAN_HT40(chan))
2041dd1de374Slin wang - Sun Microsystems - Beijing China 		spur_delta_phase =
2042dd1de374Slin wang - Sun Microsystems - Beijing China 		    ((bb_spur * 262144) / 10) &
2043dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_PHY_TIMING11_SPUR_DELTA_PHASE;
2044dd1de374Slin wang - Sun Microsystems - Beijing China 	else
2045dd1de374Slin wang - Sun Microsystems - Beijing China 		spur_delta_phase =
2046dd1de374Slin wang - Sun Microsystems - Beijing China 		    ((bb_spur * 524288) / 10) &
2047dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_PHY_TIMING11_SPUR_DELTA_PHASE;
2048dd1de374Slin wang - Sun Microsystems - Beijing China 
2049dd1de374Slin wang - Sun Microsystems - Beijing China 	denominator = IS_CHAN_2GHZ(chan) ? 44 : 40;
2050dd1de374Slin wang - Sun Microsystems - Beijing China 	spur_freq_sd = ((bb_spur_off * 2048) / denominator) & 0x3ff;
2051dd1de374Slin wang - Sun Microsystems - Beijing China 
2052dd1de374Slin wang - Sun Microsystems - Beijing China 	newVal = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
2053dd1de374Slin wang - Sun Microsystems - Beijing China 	    SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
2054dd1de374Slin wang - Sun Microsystems - Beijing China 	    SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
2055dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_TIMING11, newVal);
2056dd1de374Slin wang - Sun Microsystems - Beijing China 
2057dd1de374Slin wang - Sun Microsystems - Beijing China 	newVal = spur_subchannel_sd << AR_PHY_SFCORR_SPUR_SUBCHNL_SD_S;
2058dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_SFCORR_EXT, newVal);
2059dd1de374Slin wang - Sun Microsystems - Beijing China 
2060dd1de374Slin wang - Sun Microsystems - Beijing China 	cur_bin = -6000;
2061dd1de374Slin wang - Sun Microsystems - Beijing China 	upper = bin + 100;
2062dd1de374Slin wang - Sun Microsystems - Beijing China 	lower = bin - 100;
2063dd1de374Slin wang - Sun Microsystems - Beijing China 
2064dd1de374Slin wang - Sun Microsystems - Beijing China 	for (i = 0; i < 4; i++) {
2065dd1de374Slin wang - Sun Microsystems - Beijing China 		int pilot_mask = 0;
2066dd1de374Slin wang - Sun Microsystems - Beijing China 		int chan_mask = 0;
2067dd1de374Slin wang - Sun Microsystems - Beijing China 		int bp = 0;
2068dd1de374Slin wang - Sun Microsystems - Beijing China 		for (bp = 0; bp < 30; bp++) {
2069dd1de374Slin wang - Sun Microsystems - Beijing China 			if ((cur_bin > lower) && (cur_bin < upper)) {
2070dd1de374Slin wang - Sun Microsystems - Beijing China 				pilot_mask = pilot_mask | 0x1 << bp;
2071dd1de374Slin wang - Sun Microsystems - Beijing China 				chan_mask = chan_mask | 0x1 << bp;
2072dd1de374Slin wang - Sun Microsystems - Beijing China 			}
2073dd1de374Slin wang - Sun Microsystems - Beijing China 			cur_bin += 100;
2074dd1de374Slin wang - Sun Microsystems - Beijing China 		}
2075dd1de374Slin wang - Sun Microsystems - Beijing China 		cur_bin += inc[i];
2076dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
2077dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, chan_mask_reg[i], chan_mask);
2078dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2079dd1de374Slin wang - Sun Microsystems - Beijing China 
2080dd1de374Slin wang - Sun Microsystems - Beijing China 	cur_vit_mask = 6100;
2081dd1de374Slin wang - Sun Microsystems - Beijing China 	upper = bin + 120;
2082dd1de374Slin wang - Sun Microsystems - Beijing China 	lower = bin - 120;
2083dd1de374Slin wang - Sun Microsystems - Beijing China 
2084dd1de374Slin wang - Sun Microsystems - Beijing China 	for (i = 0; i < 123; i++) {
2085dd1de374Slin wang - Sun Microsystems - Beijing China 		if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
2086dd1de374Slin wang - Sun Microsystems - Beijing China 
2087dd1de374Slin wang - Sun Microsystems - Beijing China 			/* workaround for gcc bug #37014 */
2088dd1de374Slin wang - Sun Microsystems - Beijing China 			volatile int tmp = abs(cur_vit_mask - bin);
2089dd1de374Slin wang - Sun Microsystems - Beijing China 
2090dd1de374Slin wang - Sun Microsystems - Beijing China 			if (tmp < 75)
2091dd1de374Slin wang - Sun Microsystems - Beijing China 				mask_amt = 1;
2092dd1de374Slin wang - Sun Microsystems - Beijing China 			else
2093dd1de374Slin wang - Sun Microsystems - Beijing China 				mask_amt = 0;
2094dd1de374Slin wang - Sun Microsystems - Beijing China 			if (cur_vit_mask < 0)
2095dd1de374Slin wang - Sun Microsystems - Beijing China 				mask_m[abs(cur_vit_mask / 100)] = mask_amt;
2096dd1de374Slin wang - Sun Microsystems - Beijing China 			else
2097dd1de374Slin wang - Sun Microsystems - Beijing China 				mask_p[cur_vit_mask / 100] = mask_amt;
2098dd1de374Slin wang - Sun Microsystems - Beijing China 		}
2099dd1de374Slin wang - Sun Microsystems - Beijing China 		cur_vit_mask -= 100;
2100dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2101dd1de374Slin wang - Sun Microsystems - Beijing China 
2102dd1de374Slin wang - Sun Microsystems - Beijing China 	tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28) |
2103dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[48] << 26) | (mask_m[49] << 24) |
2104dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[50] << 22) | (mask_m[51] << 20) |
2105dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[52] << 18) | (mask_m[53] << 16) |
2106dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[54] << 14) | (mask_m[55] << 12) |
2107dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[56] << 10) | (mask_m[57] << 8) |
2108dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[58] << 6) | (mask_m[59] << 4) |
2109dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[60] << 2) | (mask_m[61] << 0);
2110dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
2111dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
2112dd1de374Slin wang - Sun Microsystems - Beijing China 
2113dd1de374Slin wang - Sun Microsystems - Beijing China 	tmp_mask = (mask_m[31] << 28) |
2114dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[32] << 26) | (mask_m[33] << 24) |
2115dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[34] << 22) | (mask_m[35] << 20) |
2116dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[36] << 18) | (mask_m[37] << 16) |
2117dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[48] << 14) | (mask_m[39] << 12) |
2118dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[40] << 10) | (mask_m[41] << 8) |
2119dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[42] << 6) | (mask_m[43] << 4) |
2120dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[44] << 2) | (mask_m[45] << 0);
2121dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
2122dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
2123dd1de374Slin wang - Sun Microsystems - Beijing China 
2124dd1de374Slin wang - Sun Microsystems - Beijing China 	tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28) |
2125dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[18] << 26) | (mask_m[18] << 24) |
2126dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[20] << 22) | (mask_m[20] << 20) |
2127dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[22] << 18) | (mask_m[22] << 16) |
2128dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[24] << 14) | (mask_m[24] << 12) |
2129dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[25] << 10) | (mask_m[26] << 8) |
2130dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[27] << 6) | (mask_m[28] << 4) |
2131dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[29] << 2) | (mask_m[30] << 0);
2132dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
2133dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
2134dd1de374Slin wang - Sun Microsystems - Beijing China 
2135dd1de374Slin wang - Sun Microsystems - Beijing China 	tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28) |
2136dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[2] << 26) | (mask_m[3] << 24) |
2137dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[4] << 22) | (mask_m[5] << 20) |
2138dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[6] << 18) | (mask_m[7] << 16) |
2139dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[8] << 14) | (mask_m[9] << 12) |
2140dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[10] << 10) | (mask_m[11] << 8) |
2141dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[12] << 6) | (mask_m[13] << 4) |
2142dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[14] << 2) | (mask_m[15] << 0);
2143dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
2144dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
2145dd1de374Slin wang - Sun Microsystems - Beijing China 
2146dd1de374Slin wang - Sun Microsystems - Beijing China 	tmp_mask = (mask_p[15] << 28) |
2147dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[14] << 26) | (mask_p[13] << 24) |
2148dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[12] << 22) | (mask_p[11] << 20) |
2149dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[10] << 18) | (mask_p[9] << 16) |
2150dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[8] << 14) | (mask_p[7] << 12) |
2151dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[6] << 10) | (mask_p[5] << 8) |
2152dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[4] << 6) | (mask_p[3] << 4) |
2153dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[2] << 2) | (mask_p[1] << 0);
2154dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
2155dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
2156dd1de374Slin wang - Sun Microsystems - Beijing China 
2157dd1de374Slin wang - Sun Microsystems - Beijing China 	tmp_mask = (mask_p[30] << 28) |
2158dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[29] << 26) | (mask_p[28] << 24) |
2159dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[27] << 22) | (mask_p[26] << 20) |
2160dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[25] << 18) | (mask_p[24] << 16) |
2161dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[23] << 14) | (mask_p[22] << 12) |
2162dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[21] << 10) | (mask_p[20] << 8) |
2163dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[19] << 6) | (mask_p[18] << 4) |
2164dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[17] << 2) | (mask_p[16] << 0);
2165dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
2166dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
2167dd1de374Slin wang - Sun Microsystems - Beijing China 
2168dd1de374Slin wang - Sun Microsystems - Beijing China 	tmp_mask = (mask_p[45] << 28) |
2169dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[44] << 26) | (mask_p[43] << 24) |
2170dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[42] << 22) | (mask_p[41] << 20) |
2171dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[40] << 18) | (mask_p[39] << 16) |
2172dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[38] << 14) | (mask_p[37] << 12) |
2173dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[36] << 10) | (mask_p[35] << 8) |
2174dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[34] << 6) | (mask_p[33] << 4) |
2175dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[32] << 2) | (mask_p[31] << 0);
2176dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
2177dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
2178dd1de374Slin wang - Sun Microsystems - Beijing China 
2179dd1de374Slin wang - Sun Microsystems - Beijing China 	tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28) |
2180dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[59] << 26) | (mask_p[58] << 24) |
2181dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[57] << 22) | (mask_p[56] << 20) |
2182dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[55] << 18) | (mask_p[54] << 16) |
2183dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[53] << 14) | (mask_p[52] << 12) |
2184dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[51] << 10) | (mask_p[50] << 8) |
2185dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[49] << 6) | (mask_p[48] << 4) |
2186dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[47] << 2) | (mask_p[46] << 0);
2187dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
2188dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
2189dd1de374Slin wang - Sun Microsystems - Beijing China }
2190dd1de374Slin wang - Sun Microsystems - Beijing China 
2191dd1de374Slin wang - Sun Microsystems - Beijing China static void
2192dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_spur_mitigate(struct ath_hal *ah, struct ath9k_channel *chan)
2193dd1de374Slin wang - Sun Microsystems - Beijing China {
2194dd1de374Slin wang - Sun Microsystems - Beijing China 	int bb_spur = AR_NO_SPUR;
2195dd1de374Slin wang - Sun Microsystems - Beijing China 	int bin, cur_bin;
2196dd1de374Slin wang - Sun Microsystems - Beijing China 	int spur_freq_sd;
2197dd1de374Slin wang - Sun Microsystems - Beijing China 	int spur_delta_phase;
2198dd1de374Slin wang - Sun Microsystems - Beijing China 	int denominator;
2199dd1de374Slin wang - Sun Microsystems - Beijing China 	int upper, lower, cur_vit_mask;
2200dd1de374Slin wang - Sun Microsystems - Beijing China 	int tmp, new;
2201dd1de374Slin wang - Sun Microsystems - Beijing China 	int i;
2202dd1de374Slin wang - Sun Microsystems - Beijing China 	int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
2203dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
2204dd1de374Slin wang - Sun Microsystems - Beijing China 	};
2205dd1de374Slin wang - Sun Microsystems - Beijing China 	int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
2206dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
2207dd1de374Slin wang - Sun Microsystems - Beijing China 	};
2208dd1de374Slin wang - Sun Microsystems - Beijing China 	int inc[4] = { 0, 100, 0, 0 };
2209dd1de374Slin wang - Sun Microsystems - Beijing China 
2210dd1de374Slin wang - Sun Microsystems - Beijing China 	int8_t mask_m[123];
2211dd1de374Slin wang - Sun Microsystems - Beijing China 	int8_t mask_p[123];
2212dd1de374Slin wang - Sun Microsystems - Beijing China 	int8_t mask_amt;
2213dd1de374Slin wang - Sun Microsystems - Beijing China 	int tmp_mask;
2214dd1de374Slin wang - Sun Microsystems - Beijing China 	int cur_bb_spur;
2215dd1de374Slin wang - Sun Microsystems - Beijing China 	boolean_t is2GHz = IS_CHAN_2GHZ(chan);
2216dd1de374Slin wang - Sun Microsystems - Beijing China 
2217dd1de374Slin wang - Sun Microsystems - Beijing China 	(void) memset(&mask_m, 0, sizeof (int8_t) * 123);
2218dd1de374Slin wang - Sun Microsystems - Beijing China 	(void) memset(&mask_p, 0, sizeof (int8_t) * 123);
2219dd1de374Slin wang - Sun Microsystems - Beijing China 
2220dd1de374Slin wang - Sun Microsystems - Beijing China 	for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
2221dd1de374Slin wang - Sun Microsystems - Beijing China 		cur_bb_spur = ath9k_hw_eeprom_get_spur_chan(ah, i, is2GHz);
2222dd1de374Slin wang - Sun Microsystems - Beijing China 		if (AR_NO_SPUR == cur_bb_spur)
2223dd1de374Slin wang - Sun Microsystems - Beijing China 			break;
2224dd1de374Slin wang - Sun Microsystems - Beijing China 		cur_bb_spur = cur_bb_spur - (chan->channel * 10);
2225dd1de374Slin wang - Sun Microsystems - Beijing China 		if ((cur_bb_spur > -95) && (cur_bb_spur < 95)) {
2226dd1de374Slin wang - Sun Microsystems - Beijing China 			bb_spur = cur_bb_spur;
2227dd1de374Slin wang - Sun Microsystems - Beijing China 			break;
2228dd1de374Slin wang - Sun Microsystems - Beijing China 		}
2229dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2230dd1de374Slin wang - Sun Microsystems - Beijing China 
2231dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_NO_SPUR == bb_spur)
2232dd1de374Slin wang - Sun Microsystems - Beijing China 		return;
2233dd1de374Slin wang - Sun Microsystems - Beijing China 
2234dd1de374Slin wang - Sun Microsystems - Beijing China 	bin = bb_spur * 32;
2235dd1de374Slin wang - Sun Microsystems - Beijing China 
2236dd1de374Slin wang - Sun Microsystems - Beijing China 	tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
2237dd1de374Slin wang - Sun Microsystems - Beijing China 	new = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
2238dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
2239dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
2240dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
2241dd1de374Slin wang - Sun Microsystems - Beijing China 
2242dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), new);
2243dd1de374Slin wang - Sun Microsystems - Beijing China 
2244dd1de374Slin wang - Sun Microsystems - Beijing China 	new = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
2245dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
2246dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_PHY_SPUR_REG_MASK_RATE_SELECT |
2247dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
2248dd1de374Slin wang - Sun Microsystems - Beijing China 	    SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
2249dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_SPUR_REG, new);
2250dd1de374Slin wang - Sun Microsystems - Beijing China 
2251dd1de374Slin wang - Sun Microsystems - Beijing China 	spur_delta_phase = ((bb_spur * 524288) / 100) &
2252dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_PHY_TIMING11_SPUR_DELTA_PHASE;
2253dd1de374Slin wang - Sun Microsystems - Beijing China 
2254dd1de374Slin wang - Sun Microsystems - Beijing China 	denominator = IS_CHAN_2GHZ(chan) ? 440 : 400;
2255dd1de374Slin wang - Sun Microsystems - Beijing China 	spur_freq_sd = ((bb_spur * 2048) / denominator) & 0x3ff;
2256dd1de374Slin wang - Sun Microsystems - Beijing China 
2257dd1de374Slin wang - Sun Microsystems - Beijing China 	new = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
2258dd1de374Slin wang - Sun Microsystems - Beijing China 	    SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
2259dd1de374Slin wang - Sun Microsystems - Beijing China 	    SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
2260dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_TIMING11, new);
2261dd1de374Slin wang - Sun Microsystems - Beijing China 
2262dd1de374Slin wang - Sun Microsystems - Beijing China 	cur_bin = -6000;
2263dd1de374Slin wang - Sun Microsystems - Beijing China 	upper = bin + 100;
2264dd1de374Slin wang - Sun Microsystems - Beijing China 	lower = bin - 100;
2265dd1de374Slin wang - Sun Microsystems - Beijing China 
2266dd1de374Slin wang - Sun Microsystems - Beijing China 	for (i = 0; i < 4; i++) {
2267dd1de374Slin wang - Sun Microsystems - Beijing China 		int pilot_mask = 0;
2268dd1de374Slin wang - Sun Microsystems - Beijing China 		int chan_mask = 0;
2269dd1de374Slin wang - Sun Microsystems - Beijing China 		int bp = 0;
2270dd1de374Slin wang - Sun Microsystems - Beijing China 		for (bp = 0; bp < 30; bp++) {
2271dd1de374Slin wang - Sun Microsystems - Beijing China 			if ((cur_bin > lower) && (cur_bin < upper)) {
2272dd1de374Slin wang - Sun Microsystems - Beijing China 				pilot_mask = pilot_mask | 0x1 << bp;
2273dd1de374Slin wang - Sun Microsystems - Beijing China 				chan_mask = chan_mask | 0x1 << bp;
2274dd1de374Slin wang - Sun Microsystems - Beijing China 			}
2275dd1de374Slin wang - Sun Microsystems - Beijing China 			cur_bin += 100;
2276dd1de374Slin wang - Sun Microsystems - Beijing China 		}
2277dd1de374Slin wang - Sun Microsystems - Beijing China 		cur_bin += inc[i];
2278dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
2279dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, chan_mask_reg[i], chan_mask);
2280dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2281dd1de374Slin wang - Sun Microsystems - Beijing China 
2282dd1de374Slin wang - Sun Microsystems - Beijing China 	cur_vit_mask = 6100;
2283dd1de374Slin wang - Sun Microsystems - Beijing China 	upper = bin + 120;
2284dd1de374Slin wang - Sun Microsystems - Beijing China 	lower = bin - 120;
2285dd1de374Slin wang - Sun Microsystems - Beijing China 
2286dd1de374Slin wang - Sun Microsystems - Beijing China 	for (i = 0; i < 123; i++) {
2287dd1de374Slin wang - Sun Microsystems - Beijing China 		if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
2288dd1de374Slin wang - Sun Microsystems - Beijing China 
2289dd1de374Slin wang - Sun Microsystems - Beijing China 			/* workaround for gcc bug #37014 */
2290dd1de374Slin wang - Sun Microsystems - Beijing China 			volatile int tmp = abs(cur_vit_mask - bin);
2291dd1de374Slin wang - Sun Microsystems - Beijing China 
2292dd1de374Slin wang - Sun Microsystems - Beijing China 			if (tmp < 75)
2293dd1de374Slin wang - Sun Microsystems - Beijing China 				mask_amt = 1;
2294dd1de374Slin wang - Sun Microsystems - Beijing China 			else
2295dd1de374Slin wang - Sun Microsystems - Beijing China 				mask_amt = 0;
2296dd1de374Slin wang - Sun Microsystems - Beijing China 			if (cur_vit_mask < 0)
2297dd1de374Slin wang - Sun Microsystems - Beijing China 				mask_m[abs(cur_vit_mask / 100)] = mask_amt;
2298dd1de374Slin wang - Sun Microsystems - Beijing China 			else
2299dd1de374Slin wang - Sun Microsystems - Beijing China 				mask_p[cur_vit_mask / 100] = mask_amt;
2300dd1de374Slin wang - Sun Microsystems - Beijing China 		}
2301dd1de374Slin wang - Sun Microsystems - Beijing China 		cur_vit_mask -= 100;
2302dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2303dd1de374Slin wang - Sun Microsystems - Beijing China 
2304dd1de374Slin wang - Sun Microsystems - Beijing China 	tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28) |
2305dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[48] << 26) | (mask_m[49] << 24) |
2306dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[50] << 22) | (mask_m[51] << 20) |
2307dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[52] << 18) | (mask_m[53] << 16) |
2308dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[54] << 14) | (mask_m[55] << 12) |
2309dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[56] << 10) | (mask_m[57] << 8) |
2310dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[58] << 6) | (mask_m[59] << 4) |
2311dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[60] << 2) | (mask_m[61] << 0);
2312dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
2313dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
2314dd1de374Slin wang - Sun Microsystems - Beijing China 
2315dd1de374Slin wang - Sun Microsystems - Beijing China 	tmp_mask = (mask_m[31] << 28) |
2316dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[32] << 26) | (mask_m[33] << 24) |
2317dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[34] << 22) | (mask_m[35] << 20) |
2318dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[36] << 18) | (mask_m[37] << 16) |
2319dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[48] << 14) | (mask_m[39] << 12) |
2320dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[40] << 10) | (mask_m[41] << 8) |
2321dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[42] << 6) | (mask_m[43] << 4) |
2322dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[44] << 2) | (mask_m[45] << 0);
2323dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
2324dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
2325dd1de374Slin wang - Sun Microsystems - Beijing China 
2326dd1de374Slin wang - Sun Microsystems - Beijing China 	tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28) |
2327dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[18] << 26) | (mask_m[18] << 24) |
2328dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[20] << 22) | (mask_m[20] << 20) |
2329dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[22] << 18) | (mask_m[22] << 16) |
2330dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[24] << 14) | (mask_m[24] << 12) |
2331dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[25] << 10) | (mask_m[26] << 8) |
2332dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[27] << 6) | (mask_m[28] << 4) |
2333dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[29] << 2) | (mask_m[30] << 0);
2334dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
2335dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
2336dd1de374Slin wang - Sun Microsystems - Beijing China 
2337dd1de374Slin wang - Sun Microsystems - Beijing China 	tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28) |
2338dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[2] << 26) | (mask_m[3] << 24) |
2339dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[4] << 22) | (mask_m[5] << 20) |
2340dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[6] << 18) | (mask_m[7] << 16) |
2341dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[8] << 14) | (mask_m[9] << 12) |
2342dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[10] << 10) | (mask_m[11] << 8) |
2343dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[12] << 6) | (mask_m[13] << 4) |
2344dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_m[14] << 2) | (mask_m[15] << 0);
2345dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
2346dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
2347dd1de374Slin wang - Sun Microsystems - Beijing China 
2348dd1de374Slin wang - Sun Microsystems - Beijing China 	tmp_mask = (mask_p[15] << 28) |
2349dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[14] << 26) | (mask_p[13] << 24) |
2350dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[12] << 22) | (mask_p[11] << 20) |
2351dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[10] << 18) | (mask_p[9] << 16) |
2352dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[8] << 14) | (mask_p[7] << 12) |
2353dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[6] << 10) | (mask_p[5] << 8) |
2354dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[4] << 6) | (mask_p[3] << 4) |
2355dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[2] << 2) | (mask_p[1] << 0);
2356dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
2357dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
2358dd1de374Slin wang - Sun Microsystems - Beijing China 
2359dd1de374Slin wang - Sun Microsystems - Beijing China 	tmp_mask = (mask_p[30] << 28) |
2360dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[29] << 26) | (mask_p[28] << 24) |
2361dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[27] << 22) | (mask_p[26] << 20) |
2362dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[25] << 18) | (mask_p[24] << 16) |
2363dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[23] << 14) | (mask_p[22] << 12) |
2364dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[21] << 10) | (mask_p[20] << 8) |
2365dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[19] << 6) | (mask_p[18] << 4) |
2366dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[17] << 2) | (mask_p[16] << 0);
2367dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
2368dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
2369dd1de374Slin wang - Sun Microsystems - Beijing China 
2370dd1de374Slin wang - Sun Microsystems - Beijing China 	tmp_mask = (mask_p[45] << 28) |
2371dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[44] << 26) | (mask_p[43] << 24) |
2372dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[42] << 22) | (mask_p[41] << 20) |
2373dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[40] << 18) | (mask_p[39] << 16) |
2374dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[38] << 14) | (mask_p[37] << 12) |
2375dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[36] << 10) | (mask_p[35] << 8) |
2376dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[34] << 6) | (mask_p[33] << 4) |
2377dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[32] << 2) | (mask_p[31] << 0);
2378dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
2379dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
2380dd1de374Slin wang - Sun Microsystems - Beijing China 
2381dd1de374Slin wang - Sun Microsystems - Beijing China 	tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28) |
2382dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[59] << 26) | (mask_p[58] << 24) |
2383dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[57] << 22) | (mask_p[56] << 20) |
2384dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[55] << 18) | (mask_p[54] << 16) |
2385dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[53] << 14) | (mask_p[52] << 12) |
2386dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[51] << 10) | (mask_p[50] << 8) |
2387dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[49] << 6) | (mask_p[48] << 4) |
2388dd1de374Slin wang - Sun Microsystems - Beijing China 	    (mask_p[47] << 2) | (mask_p[46] << 0);
2389dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
2390dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
2391dd1de374Slin wang - Sun Microsystems - Beijing China }
2392dd1de374Slin wang - Sun Microsystems - Beijing China 
2393dd1de374Slin wang - Sun Microsystems - Beijing China boolean_t
2394dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_reset(struct ath_hal *ah, struct ath9k_channel *chan,
2395dd1de374Slin wang - Sun Microsystems - Beijing China     enum ath9k_ht_macmode macmode,
2396dd1de374Slin wang - Sun Microsystems - Beijing China     uint8_t txchainmask, uint8_t rxchainmask,
2397dd1de374Slin wang - Sun Microsystems - Beijing China     enum ath9k_ht_extprotspacing extprotspacing,
2398dd1de374Slin wang - Sun Microsystems - Beijing China     boolean_t bChannelChange, int *status)
2399dd1de374Slin wang - Sun Microsystems - Beijing China {
2400dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t saveLedState;
2401dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
2402dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath9k_channel *curchan = ah->ah_curchan;
2403dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t saveDefAntenna;
2404dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t macStaId1;
2405dd1de374Slin wang - Sun Microsystems - Beijing China 	int ecode;
2406dd1de374Slin wang - Sun Microsystems - Beijing China 	int i, rx_chainmask;
2407dd1de374Slin wang - Sun Microsystems - Beijing China 
2408dd1de374Slin wang - Sun Microsystems - Beijing China 	ahp->ah_extprotspacing = extprotspacing;
2409dd1de374Slin wang - Sun Microsystems - Beijing China 	ahp->ah_txchainmask = txchainmask;
2410dd1de374Slin wang - Sun Microsystems - Beijing China 	ahp->ah_rxchainmask = rxchainmask;
2411dd1de374Slin wang - Sun Microsystems - Beijing China 
2412dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9280(ah)) {
2413dd1de374Slin wang - Sun Microsystems - Beijing China 		ahp->ah_txchainmask &= 0x3;
2414dd1de374Slin wang - Sun Microsystems - Beijing China 		ahp->ah_rxchainmask &= 0x3;
2415dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2416dd1de374Slin wang - Sun Microsystems - Beijing China 
2417dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ath9k_hw_check_chan(ah, chan) == NULL) {
2418dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_ANY, "arn: "
2419dd1de374Slin wang - Sun Microsystems - Beijing China 		    "%s: invalid channel %u/0x%x; no mapping\n",
2420dd1de374Slin wang - Sun Microsystems - Beijing China 		    __func__, chan->channel, chan->channelFlags));
2421dd1de374Slin wang - Sun Microsystems - Beijing China 		ecode = EINVAL;
2422dd1de374Slin wang - Sun Microsystems - Beijing China 		goto bad;
2423dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2424dd1de374Slin wang - Sun Microsystems - Beijing China 
2425dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
2426dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_ANY, "arn: "
2427dd1de374Slin wang - Sun Microsystems - Beijing China 		    "%s: ath9k_hw_setpower failed!!!\n", __func__));
2428dd1de374Slin wang - Sun Microsystems - Beijing China 		ecode = EIO;
2429dd1de374Slin wang - Sun Microsystems - Beijing China 		goto bad;
2430dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2431dd1de374Slin wang - Sun Microsystems - Beijing China 
2432dd1de374Slin wang - Sun Microsystems - Beijing China 	if (curchan)
2433dd1de374Slin wang - Sun Microsystems - Beijing China 		(void) ath9k_hw_getnf(ah, curchan);
2434dd1de374Slin wang - Sun Microsystems - Beijing China 
2435dd1de374Slin wang - Sun Microsystems - Beijing China 	if (bChannelChange &&
2436dd1de374Slin wang - Sun Microsystems - Beijing China 	    (ahp->ah_chipFullSleep != B_TRUE) &&
2437dd1de374Slin wang - Sun Microsystems - Beijing China 	    (ah->ah_curchan != NULL) &&
2438dd1de374Slin wang - Sun Microsystems - Beijing China 	    (chan->channel != ah->ah_curchan->channel) &&
2439dd1de374Slin wang - Sun Microsystems - Beijing China 	    ((chan->channelFlags & CHANNEL_ALL) ==
2440dd1de374Slin wang - Sun Microsystems - Beijing China 	    (ah->ah_curchan->channelFlags & CHANNEL_ALL)) &&
2441dd1de374Slin wang - Sun Microsystems - Beijing China 	    (!AR_SREV_9280(ah) || (!IS_CHAN_A_5MHZ_SPACED(chan) &&
2442dd1de374Slin wang - Sun Microsystems - Beijing China 	    !IS_CHAN_A_5MHZ_SPACED(ah->ah_curchan)))) {
2443dd1de374Slin wang - Sun Microsystems - Beijing China 
2444dd1de374Slin wang - Sun Microsystems - Beijing China 		if (ath9k_hw_channel_change(ah, chan, macmode)) {
2445dd1de374Slin wang - Sun Microsystems - Beijing China 			ath9k_hw_loadnf(ah, ah->ah_curchan);
2446dd1de374Slin wang - Sun Microsystems - Beijing China 			ath9k_hw_start_nfcal(ah);
2447dd1de374Slin wang - Sun Microsystems - Beijing China 			return (B_TRUE);
2448dd1de374Slin wang - Sun Microsystems - Beijing China 		}
2449dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2450dd1de374Slin wang - Sun Microsystems - Beijing China 
2451dd1de374Slin wang - Sun Microsystems - Beijing China 	saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
2452dd1de374Slin wang - Sun Microsystems - Beijing China 	if (saveDefAntenna == 0)
2453dd1de374Slin wang - Sun Microsystems - Beijing China 		saveDefAntenna = 1;
2454dd1de374Slin wang - Sun Microsystems - Beijing China 
2455dd1de374Slin wang - Sun Microsystems - Beijing China 	macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
2456dd1de374Slin wang - Sun Microsystems - Beijing China 
2457dd1de374Slin wang - Sun Microsystems - Beijing China 	saveLedState = REG_READ(ah, AR_CFG_LED) &
2458dd1de374Slin wang - Sun Microsystems - Beijing China 	    (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
2459dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
2460dd1de374Slin wang - Sun Microsystems - Beijing China 
2461dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_mark_phy_inactive(ah);
2462dd1de374Slin wang - Sun Microsystems - Beijing China 
2463dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!ath9k_hw_chip_reset(ah, chan)) {
2464dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_RESET, "arn: "
2465dd1de374Slin wang - Sun Microsystems - Beijing China 		    "%s: chip reset failed\n", __func__));
2466dd1de374Slin wang - Sun Microsystems - Beijing China 		ecode = EINVAL;
2467dd1de374Slin wang - Sun Microsystems - Beijing China 		goto bad;
2468dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2469dd1de374Slin wang - Sun Microsystems - Beijing China 
2470dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9280(ah)) {
2471dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
2472dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_GPIO_JTAG_DISABLE);
2473dd1de374Slin wang - Sun Microsystems - Beijing China 		if (is_set(ATH9K_MODE_11A, ah->ah_caps.wireless_modes)) {
2474dd1de374Slin wang - Sun Microsystems - Beijing China 			if (IS_CHAN_5GHZ(chan))
2475dd1de374Slin wang - Sun Microsystems - Beijing China 				ath9k_hw_set_gpio(ah, 9, 0);
2476dd1de374Slin wang - Sun Microsystems - Beijing China 			else
2477dd1de374Slin wang - Sun Microsystems - Beijing China 				ath9k_hw_set_gpio(ah, 9, 1);
2478dd1de374Slin wang - Sun Microsystems - Beijing China 		}
2479dd1de374Slin wang - Sun Microsystems - Beijing China 		ath9k_hw_cfg_output(ah, 9, AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
2480dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2481dd1de374Slin wang - Sun Microsystems - Beijing China 
2482dd1de374Slin wang - Sun Microsystems - Beijing China 	ecode = ath9k_hw_process_ini(ah, chan, macmode);
2483dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ecode != 0) {
2484dd1de374Slin wang - Sun Microsystems - Beijing China 		ecode = EINVAL;
2485dd1de374Slin wang - Sun Microsystems - Beijing China 		goto bad;
2486dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2487dd1de374Slin wang - Sun Microsystems - Beijing China 
2488dd1de374Slin wang - Sun Microsystems - Beijing China 	if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
2489dd1de374Slin wang - Sun Microsystems - Beijing China 		ath9k_hw_set_delta_slope(ah, chan);
2490dd1de374Slin wang - Sun Microsystems - Beijing China 
2491dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9280_10_OR_LATER(ah))
2492dd1de374Slin wang - Sun Microsystems - Beijing China 		ath9k_hw_9280_spur_mitigate(ah, chan);
2493dd1de374Slin wang - Sun Microsystems - Beijing China 	else
2494dd1de374Slin wang - Sun Microsystems - Beijing China 		ath9k_hw_spur_mitigate(ah, chan);
2495dd1de374Slin wang - Sun Microsystems - Beijing China 
2496dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!ath9k_hw_eeprom_set_board_values(ah, chan)) {
2497dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_EEPROM, "arn: "
2498dd1de374Slin wang - Sun Microsystems - Beijing China 		    "%s: error setting board options\n", __func__));
2499dd1de374Slin wang - Sun Microsystems - Beijing China 		ecode = EIO;
2500dd1de374Slin wang - Sun Microsystems - Beijing China 		goto bad;
2501dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2502dd1de374Slin wang - Sun Microsystems - Beijing China 
2503dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_decrease_chain_power(ah, chan);
2504dd1de374Slin wang - Sun Microsystems - Beijing China 
2505dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_STA_ID0, ARN_LE_READ_32(ahp->ah_macaddr));
2506dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_STA_ID1, ARN_LE_READ_16(ahp->ah_macaddr + 4) |
2507dd1de374Slin wang - Sun Microsystems - Beijing China 	    macStaId1 |
2508dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_STA_ID1_RTS_USE_DEF |
2509dd1de374Slin wang - Sun Microsystems - Beijing China 	    (ah->ah_config.ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0) |
2510dd1de374Slin wang - Sun Microsystems - Beijing China 	    ahp->ah_staId1Defaults);
2511dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_set_operating_mode(ah, ah->ah_opmode);
2512dd1de374Slin wang - Sun Microsystems - Beijing China 
2513dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_BSSMSKL, ARN_LE_READ_32(ahp->ah_bssidmask));
2514dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_BSSMSKU, ARN_LE_READ_16(ahp->ah_bssidmask + 4));
2515dd1de374Slin wang - Sun Microsystems - Beijing China 
2516dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
2517dd1de374Slin wang - Sun Microsystems - Beijing China 
2518dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_BSS_ID0, ARN_LE_READ_32(ahp->ah_bssid));
2519dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_BSS_ID1, ARN_LE_READ_16(ahp->ah_bssid + 4) |
2520dd1de374Slin wang - Sun Microsystems - Beijing China 	    ((ahp->ah_assocId & 0x3fff) << AR_BSS_ID1_AID_S));
2521dd1de374Slin wang - Sun Microsystems - Beijing China 
2522dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_ISR, ~0);
2523dd1de374Slin wang - Sun Microsystems - Beijing China 
2524dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
2525dd1de374Slin wang - Sun Microsystems - Beijing China 
2526dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9280_10_OR_LATER(ah)) {
2527dd1de374Slin wang - Sun Microsystems - Beijing China 		if (!(ath9k_hw_ar9280_set_channel(ah, chan))) {
2528dd1de374Slin wang - Sun Microsystems - Beijing China 			ARN_DBG((ARN_DBG_FATAL, "arn: "
2529dd1de374Slin wang - Sun Microsystems - Beijing China 			    "%s: ath9k_hw_ar9280_set_channel failed!!!\n",
2530dd1de374Slin wang - Sun Microsystems - Beijing China 			    __func__));
2531dd1de374Slin wang - Sun Microsystems - Beijing China 			ecode = EIO;
2532dd1de374Slin wang - Sun Microsystems - Beijing China 			goto bad;
2533dd1de374Slin wang - Sun Microsystems - Beijing China 		}
2534dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
2535dd1de374Slin wang - Sun Microsystems - Beijing China 		if (!(ath9k_hw_set_channel(ah, chan))) {
2536dd1de374Slin wang - Sun Microsystems - Beijing China 			ARN_DBG((ARN_DBG_FATAL, "arn: "
2537dd1de374Slin wang - Sun Microsystems - Beijing China 			    "%s: ath9k_hw_set_channel failed!!!\n", __func__));
2538dd1de374Slin wang - Sun Microsystems - Beijing China 			ecode = EIO;
2539dd1de374Slin wang - Sun Microsystems - Beijing China 			goto bad;
2540dd1de374Slin wang - Sun Microsystems - Beijing China 		}
2541dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2542dd1de374Slin wang - Sun Microsystems - Beijing China 
2543dd1de374Slin wang - Sun Microsystems - Beijing China 	for (i = 0; i < AR_NUM_DCU; i++)
2544dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
2545dd1de374Slin wang - Sun Microsystems - Beijing China 
2546dd1de374Slin wang - Sun Microsystems - Beijing China 	ahp->ah_intrTxqs = 0;
2547dd1de374Slin wang - Sun Microsystems - Beijing China 	for (i = 0; i < ah->ah_caps.total_queues; i++)
2548dd1de374Slin wang - Sun Microsystems - Beijing China 		(void) ath9k_hw_resettxqueue(ah, i);
2549dd1de374Slin wang - Sun Microsystems - Beijing China 
2550dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_init_interrupt_masks(ah, ah->ah_opmode);
2551dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_init_qos(ah);
2552dd1de374Slin wang - Sun Microsystems - Beijing China 
2553dd1de374Slin wang - Sun Microsystems - Beijing China #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
2554dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
2555dd1de374Slin wang - Sun Microsystems - Beijing China 		ath9k_enable_rfkill(ah);
2556dd1de374Slin wang - Sun Microsystems - Beijing China #endif
2557dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_init_user_settings(ah);
2558dd1de374Slin wang - Sun Microsystems - Beijing China 
2559dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_STA_ID1,
2560dd1de374Slin wang - Sun Microsystems - Beijing China 	    REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM);
2561dd1de374Slin wang - Sun Microsystems - Beijing China 
2562dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_set_dma(ah);
2563dd1de374Slin wang - Sun Microsystems - Beijing China 
2564dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_OBS, 8);
2565dd1de374Slin wang - Sun Microsystems - Beijing China 
2566dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ahp->ah_intrMitigation) {
2567dd1de374Slin wang - Sun Microsystems - Beijing China 
2568dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
2569dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
2570dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2571dd1de374Slin wang - Sun Microsystems - Beijing China 
2572dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_init_bb(ah, chan);
2573dd1de374Slin wang - Sun Microsystems - Beijing China 
2574dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!ath9k_hw_init_cal(ah, chan)) {
2575dd1de374Slin wang - Sun Microsystems - Beijing China 		ecode = EIO;
2576dd1de374Slin wang - Sun Microsystems - Beijing China 		goto bad;
2577dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2578dd1de374Slin wang - Sun Microsystems - Beijing China 
2579dd1de374Slin wang - Sun Microsystems - Beijing China 	rx_chainmask = ahp->ah_rxchainmask;
2580dd1de374Slin wang - Sun Microsystems - Beijing China 	if ((rx_chainmask == 0x5) || (rx_chainmask == 0x3)) {
2581dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
2582dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
2583dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2584dd1de374Slin wang - Sun Microsystems - Beijing China 
2585dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
2586dd1de374Slin wang - Sun Microsystems - Beijing China 
2587dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9100(ah)) {
2588dd1de374Slin wang - Sun Microsystems - Beijing China 		uint32_t mask;
2589dd1de374Slin wang - Sun Microsystems - Beijing China 		mask = REG_READ(ah, AR_CFG);
2590dd1de374Slin wang - Sun Microsystems - Beijing China 		if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
2591dd1de374Slin wang - Sun Microsystems - Beijing China 			ARN_DBG((ARN_DBG_RESET, "arn: "
2592dd1de374Slin wang - Sun Microsystems - Beijing China 			    "%s CFG Byte Swap Set 0x%x\n",
2593dd1de374Slin wang - Sun Microsystems - Beijing China 			    __func__, mask));
2594dd1de374Slin wang - Sun Microsystems - Beijing China 		} else {
2595dd1de374Slin wang - Sun Microsystems - Beijing China 			mask = INIT_CONFIG_STATUS |
2596dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR_CFG_SWRB | AR_CFG_SWTB;
2597dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_WRITE(ah, AR_CFG, mask);
2598dd1de374Slin wang - Sun Microsystems - Beijing China 			ARN_DBG((ARN_DBG_RESET, "arn: "
2599dd1de374Slin wang - Sun Microsystems - Beijing China 			    "%s Setting CFG 0x%x\n",
2600dd1de374Slin wang - Sun Microsystems - Beijing China 			    __func__, REG_READ(ah, AR_CFG)));
2601dd1de374Slin wang - Sun Microsystems - Beijing China 		}
2602dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
2603dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_HW, "arn: ath9k_hw_keyreset(): "
2604dd1de374Slin wang - Sun Microsystems - Beijing China 		    "#ifdef __BIG_ENDIAN \n"));
2605dd1de374Slin wang - Sun Microsystems - Beijing China #ifdef __BIG_ENDIAN
2606dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
2607dd1de374Slin wang - Sun Microsystems - Beijing China #endif
2608dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2609dd1de374Slin wang - Sun Microsystems - Beijing China 
2610dd1de374Slin wang - Sun Microsystems - Beijing China 	return (B_TRUE);
2611dd1de374Slin wang - Sun Microsystems - Beijing China bad:
2612dd1de374Slin wang - Sun Microsystems - Beijing China 	if (status)
2613dd1de374Slin wang - Sun Microsystems - Beijing China 		*status = ecode;
2614dd1de374Slin wang - Sun Microsystems - Beijing China 	return (B_FALSE);
2615dd1de374Slin wang - Sun Microsystems - Beijing China }
2616dd1de374Slin wang - Sun Microsystems - Beijing China 
2617dd1de374Slin wang - Sun Microsystems - Beijing China /* Key Cache Management */
2618dd1de374Slin wang - Sun Microsystems - Beijing China 
2619dd1de374Slin wang - Sun Microsystems - Beijing China boolean_t
2620dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_keyreset(struct ath_hal *ah, uint16_t entry)
2621dd1de374Slin wang - Sun Microsystems - Beijing China {
2622dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t keyType;
2623dd1de374Slin wang - Sun Microsystems - Beijing China 
2624dd1de374Slin wang - Sun Microsystems - Beijing China 	if (entry >= ah->ah_caps.keycache_size) {
2625dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_KEYCACHE, "arn: ath9k_hw_keyreset(): "
2626dd1de374Slin wang - Sun Microsystems - Beijing China 		    "entry %u out of range\n", entry));
2627dd1de374Slin wang - Sun Microsystems - Beijing China 
2628dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_FALSE);
2629dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2630dd1de374Slin wang - Sun Microsystems - Beijing China 
2631dd1de374Slin wang - Sun Microsystems - Beijing China 	keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
2632dd1de374Slin wang - Sun Microsystems - Beijing China 
2633dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
2634dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
2635dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
2636dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
2637dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
2638dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
2639dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
2640dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
2641dd1de374Slin wang - Sun Microsystems - Beijing China 
2642dd1de374Slin wang - Sun Microsystems - Beijing China 	if (keyType == AR_KEYTABLE_TYPE_TKIP &&
2643dd1de374Slin wang - Sun Microsystems - Beijing China 	    ATH9K_IS_MIC_ENABLED(ah)) {
2644dd1de374Slin wang - Sun Microsystems - Beijing China 		uint16_t micentry = entry + 64;
2645dd1de374Slin wang - Sun Microsystems - Beijing China 
2646dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
2647dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
2648dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
2649dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
2650dd1de374Slin wang - Sun Microsystems - Beijing China 
2651dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2652dd1de374Slin wang - Sun Microsystems - Beijing China 
2653dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ah->ah_curchan == NULL)
2654dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_TRUE);
2655dd1de374Slin wang - Sun Microsystems - Beijing China 
2656dd1de374Slin wang - Sun Microsystems - Beijing China 	return (B_TRUE);
2657dd1de374Slin wang - Sun Microsystems - Beijing China }
2658dd1de374Slin wang - Sun Microsystems - Beijing China 
2659dd1de374Slin wang - Sun Microsystems - Beijing China boolean_t
2660dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_keysetmac(struct ath_hal *ah, uint16_t entry, const uint8_t *mac)
2661dd1de374Slin wang - Sun Microsystems - Beijing China {
2662dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t macHi, macLo;
2663dd1de374Slin wang - Sun Microsystems - Beijing China 
2664dd1de374Slin wang - Sun Microsystems - Beijing China 	if (entry >= ah->ah_caps.keycache_size) {
2665dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_KEYCACHE, "arn: "
2666dd1de374Slin wang - Sun Microsystems - Beijing China 		    "%s: entry %u out of range\n", __func__, entry));
2667dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_FALSE);
2668dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2669dd1de374Slin wang - Sun Microsystems - Beijing China 
2670dd1de374Slin wang - Sun Microsystems - Beijing China 	if (mac != NULL) {
2671dd1de374Slin wang - Sun Microsystems - Beijing China 		macHi = (mac[5] << 8) | mac[4];
2672dd1de374Slin wang - Sun Microsystems - Beijing China 		macLo = (mac[3] << 24) |
2673dd1de374Slin wang - Sun Microsystems - Beijing China 		    (mac[2] << 16) |
2674dd1de374Slin wang - Sun Microsystems - Beijing China 		    (mac[1] << 8) |
2675dd1de374Slin wang - Sun Microsystems - Beijing China 		    mac[0];
2676dd1de374Slin wang - Sun Microsystems - Beijing China 		macLo >>= 1;
2677dd1de374Slin wang - Sun Microsystems - Beijing China 		macLo |= (macHi & 1) << 31;
2678dd1de374Slin wang - Sun Microsystems - Beijing China 		macHi >>= 1;
2679dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
2680dd1de374Slin wang - Sun Microsystems - Beijing China 		macLo = macHi = 0;
2681dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2682dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
2683dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
2684dd1de374Slin wang - Sun Microsystems - Beijing China 
2685dd1de374Slin wang - Sun Microsystems - Beijing China 	return (B_TRUE);
2686dd1de374Slin wang - Sun Microsystems - Beijing China }
2687dd1de374Slin wang - Sun Microsystems - Beijing China 
2688dd1de374Slin wang - Sun Microsystems - Beijing China boolean_t
2689dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_set_keycache_entry(struct ath_hal *ah, uint16_t entry,
2690dd1de374Slin wang - Sun Microsystems - Beijing China     const struct ath9k_keyval *k, const uint8_t *mac, int xorKey)
2691dd1de374Slin wang - Sun Microsystems - Beijing China {
2692dd1de374Slin wang - Sun Microsystems - Beijing China 	const struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
2693dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t key0, key1, key2, key3, key4;
2694dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t keyType;
2695dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t xorMask = xorKey ?
2696dd1de374Slin wang - Sun Microsystems - Beijing China 	    (ATH9K_KEY_XOR << 24 | ATH9K_KEY_XOR << 16 |
2697dd1de374Slin wang - Sun Microsystems - Beijing China 	    ATH9K_KEY_XOR << 8 | ATH9K_KEY_XOR) : 0;
2698dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
2699dd1de374Slin wang - Sun Microsystems - Beijing China 
2700dd1de374Slin wang - Sun Microsystems - Beijing China 	if (entry >= pCap->keycache_size) {
2701dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_KEYCACHE, "arn: "
2702dd1de374Slin wang - Sun Microsystems - Beijing China 		    "%s: entry %u out of range\n", __func__, entry));
2703dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_FALSE);
2704dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2705dd1de374Slin wang - Sun Microsystems - Beijing China 
2706dd1de374Slin wang - Sun Microsystems - Beijing China 	switch (k->kv_type) {
2707dd1de374Slin wang - Sun Microsystems - Beijing China 	case ATH9K_CIPHER_AES_OCB:
2708dd1de374Slin wang - Sun Microsystems - Beijing China 		keyType = AR_KEYTABLE_TYPE_AES;
2709dd1de374Slin wang - Sun Microsystems - Beijing China 		break;
2710dd1de374Slin wang - Sun Microsystems - Beijing China 	case ATH9K_CIPHER_AES_CCM:
2711dd1de374Slin wang - Sun Microsystems - Beijing China 		if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
2712dd1de374Slin wang - Sun Microsystems - Beijing China 			ARN_DBG((ARN_DBG_KEYCACHE, "arn: "
2713dd1de374Slin wang - Sun Microsystems - Beijing China 			    "%s: AES-CCM not supported by "
2714dd1de374Slin wang - Sun Microsystems - Beijing China 			    "mac rev 0x%x\n", __func__,
2715dd1de374Slin wang - Sun Microsystems - Beijing China 			    ah->ah_macRev));
2716dd1de374Slin wang - Sun Microsystems - Beijing China 			return (B_FALSE);
2717dd1de374Slin wang - Sun Microsystems - Beijing China 		}
2718dd1de374Slin wang - Sun Microsystems - Beijing China 		keyType = AR_KEYTABLE_TYPE_CCM;
2719dd1de374Slin wang - Sun Microsystems - Beijing China 		break;
2720dd1de374Slin wang - Sun Microsystems - Beijing China 	case ATH9K_CIPHER_TKIP:
2721dd1de374Slin wang - Sun Microsystems - Beijing China 		keyType = AR_KEYTABLE_TYPE_TKIP;
2722dd1de374Slin wang - Sun Microsystems - Beijing China 		if (ATH9K_IS_MIC_ENABLED(ah) &&
2723dd1de374Slin wang - Sun Microsystems - Beijing China 		    entry + 64 >= pCap->keycache_size) {
2724dd1de374Slin wang - Sun Microsystems - Beijing China 			ARN_DBG((ARN_DBG_KEYCACHE, "arn: "
2725dd1de374Slin wang - Sun Microsystems - Beijing China 			    "%s: entry %u inappropriate for TKIP\n",
2726dd1de374Slin wang - Sun Microsystems - Beijing China 			    __func__, entry));
2727dd1de374Slin wang - Sun Microsystems - Beijing China 			return (B_FALSE);
2728dd1de374Slin wang - Sun Microsystems - Beijing China 		}
2729dd1de374Slin wang - Sun Microsystems - Beijing China 		break;
2730dd1de374Slin wang - Sun Microsystems - Beijing China 	case ATH9K_CIPHER_WEP:
2731dd1de374Slin wang - Sun Microsystems - Beijing China 		if (k->kv_len < ATH9K_LEN_WEP40) {
2732dd1de374Slin wang - Sun Microsystems - Beijing China 			ARN_DBG((ARN_DBG_KEYCACHE, "arn: "
2733dd1de374Slin wang - Sun Microsystems - Beijing China 			    "%s: WEP key length %u too small\n",
2734dd1de374Slin wang - Sun Microsystems - Beijing China 			    __func__, k->kv_len));
2735dd1de374Slin wang - Sun Microsystems - Beijing China 			return (B_FALSE);
2736dd1de374Slin wang - Sun Microsystems - Beijing China 		}
2737dd1de374Slin wang - Sun Microsystems - Beijing China 		if (k->kv_len <= ATH9K_LEN_WEP40)
2738dd1de374Slin wang - Sun Microsystems - Beijing China 			keyType = AR_KEYTABLE_TYPE_40;
2739dd1de374Slin wang - Sun Microsystems - Beijing China 		else if (k->kv_len <= ATH9K_LEN_WEP104)
2740dd1de374Slin wang - Sun Microsystems - Beijing China 			keyType = AR_KEYTABLE_TYPE_104;
2741dd1de374Slin wang - Sun Microsystems - Beijing China 		else
2742dd1de374Slin wang - Sun Microsystems - Beijing China 			keyType = AR_KEYTABLE_TYPE_128;
2743dd1de374Slin wang - Sun Microsystems - Beijing China 		break;
2744dd1de374Slin wang - Sun Microsystems - Beijing China 	case ATH9K_CIPHER_CLR:
2745dd1de374Slin wang - Sun Microsystems - Beijing China 		keyType = AR_KEYTABLE_TYPE_CLR;
2746dd1de374Slin wang - Sun Microsystems - Beijing China 		break;
2747dd1de374Slin wang - Sun Microsystems - Beijing China 	default:
2748dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_KEYCACHE, "arn: "
2749dd1de374Slin wang - Sun Microsystems - Beijing China 		    "%s: cipher %u not supported\n", __func__,
2750dd1de374Slin wang - Sun Microsystems - Beijing China 		    k->kv_type));
2751dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_FALSE);
2752dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2753dd1de374Slin wang - Sun Microsystems - Beijing China 
2754dd1de374Slin wang - Sun Microsystems - Beijing China 	key0 = ARN_LE_READ_32(k->kv_val + 0) ^ xorMask;
2755dd1de374Slin wang - Sun Microsystems - Beijing China 	key1 = (ARN_LE_READ_16(k->kv_val + 4) ^ xorMask) & 0xffff;
2756dd1de374Slin wang - Sun Microsystems - Beijing China 	key2 = ARN_LE_READ_32(k->kv_val + 6) ^ xorMask;
2757dd1de374Slin wang - Sun Microsystems - Beijing China 	key3 = (ARN_LE_READ_16(k->kv_val + 10) ^ xorMask) & 0xffff;
2758dd1de374Slin wang - Sun Microsystems - Beijing China 	key4 = ARN_LE_READ_32(k->kv_val + 12) ^ xorMask;
2759dd1de374Slin wang - Sun Microsystems - Beijing China 
2760dd1de374Slin wang - Sun Microsystems - Beijing China 	if (k->kv_len <= ATH9K_LEN_WEP104)
2761dd1de374Slin wang - Sun Microsystems - Beijing China 		key4 &= 0xff;
2762dd1de374Slin wang - Sun Microsystems - Beijing China 
2763dd1de374Slin wang - Sun Microsystems - Beijing China 	if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2764dd1de374Slin wang - Sun Microsystems - Beijing China 		uint16_t micentry = entry + 64;
2765dd1de374Slin wang - Sun Microsystems - Beijing China 
2766dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
2767dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
2768dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2769dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
2770dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2771dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
2772dd1de374Slin wang - Sun Microsystems - Beijing China 		(void) ath9k_hw_keysetmac(ah, entry, mac);
2773dd1de374Slin wang - Sun Microsystems - Beijing China 
2774dd1de374Slin wang - Sun Microsystems - Beijing China 		if (ahp->ah_miscMode & AR_PCU_MIC_NEW_LOC_ENA) {
2775dd1de374Slin wang - Sun Microsystems - Beijing China 			uint32_t mic0, mic1, mic2, mic3, mic4;
2776dd1de374Slin wang - Sun Microsystems - Beijing China 			mic0 = ARN_LE_READ_32(k->kv_mic + 0);
2777dd1de374Slin wang - Sun Microsystems - Beijing China 			mic2 = ARN_LE_READ_32(k->kv_mic + 4);
2778dd1de374Slin wang - Sun Microsystems - Beijing China 			mic1 = ARN_LE_READ_16(k->kv_txmic + 2) & 0xffff;
2779dd1de374Slin wang - Sun Microsystems - Beijing China 			mic3 = ARN_LE_READ_16(k->kv_txmic + 0) & 0xffff;
2780dd1de374Slin wang - Sun Microsystems - Beijing China 			mic4 = ARN_LE_READ_32(k->kv_txmic + 4);
2781dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2782dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
2783dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2784dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
2785dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
2786dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2787dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR_KEYTABLE_TYPE_CLR);
2788dd1de374Slin wang - Sun Microsystems - Beijing China 
2789dd1de374Slin wang - Sun Microsystems - Beijing China 		} else {
2790dd1de374Slin wang - Sun Microsystems - Beijing China 			uint32_t mic0, mic2;
2791dd1de374Slin wang - Sun Microsystems - Beijing China 			mic0 = ARN_LE_READ_32(k->kv_mic + 0);
2792dd1de374Slin wang - Sun Microsystems - Beijing China 			mic2 = ARN_LE_READ_32(k->kv_mic + 4);
2793dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2794dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
2795dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2796dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
2797dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
2798dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2799dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR_KEYTABLE_TYPE_CLR);
2800dd1de374Slin wang - Sun Microsystems - Beijing China 		}
2801dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
2802dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
2803dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2804dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
2805dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
2806dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2807dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
2808dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2809dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
2810dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2811dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
2812dd1de374Slin wang - Sun Microsystems - Beijing China 
2813dd1de374Slin wang - Sun Microsystems - Beijing China 		(void) ath9k_hw_keysetmac(ah, entry, mac);
2814dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2815dd1de374Slin wang - Sun Microsystems - Beijing China 
2816dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ah->ah_curchan == NULL)
2817dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_TRUE);
2818dd1de374Slin wang - Sun Microsystems - Beijing China 
2819dd1de374Slin wang - Sun Microsystems - Beijing China 	return (B_TRUE);
2820dd1de374Slin wang - Sun Microsystems - Beijing China }
2821dd1de374Slin wang - Sun Microsystems - Beijing China 
2822dd1de374Slin wang - Sun Microsystems - Beijing China boolean_t
2823dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_keyisvalid(struct ath_hal *ah, uint16_t entry)
2824dd1de374Slin wang - Sun Microsystems - Beijing China {
2825dd1de374Slin wang - Sun Microsystems - Beijing China 	if (entry < ah->ah_caps.keycache_size) {
2826dd1de374Slin wang - Sun Microsystems - Beijing China 		uint32_t val = REG_READ(ah, AR_KEYTABLE_MAC1(entry));
2827dd1de374Slin wang - Sun Microsystems - Beijing China 		if (val & AR_KEYTABLE_VALID)
2828dd1de374Slin wang - Sun Microsystems - Beijing China 			return (B_TRUE);
2829dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2830dd1de374Slin wang - Sun Microsystems - Beijing China 	return (B_FALSE);
2831dd1de374Slin wang - Sun Microsystems - Beijing China }
2832dd1de374Slin wang - Sun Microsystems - Beijing China 
2833dd1de374Slin wang - Sun Microsystems - Beijing China /* Power Management (Chipset) */
2834dd1de374Slin wang - Sun Microsystems - Beijing China 
2835dd1de374Slin wang - Sun Microsystems - Beijing China static void
2836dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_set_power_sleep(struct ath_hal *ah, int setChip)
2837dd1de374Slin wang - Sun Microsystems - Beijing China {
2838dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2839dd1de374Slin wang - Sun Microsystems - Beijing China 	if (setChip) {
2840dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2841dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_RTC_FORCE_WAKE_EN);
2842dd1de374Slin wang - Sun Microsystems - Beijing China 		if (!AR_SREV_9100(ah))
2843dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
2844dd1de374Slin wang - Sun Microsystems - Beijing China 
2845dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_CLR_BIT(ah, (uint16_t)(AR_RTC_RESET),
2846dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_RTC_RESET_EN);
2847dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2848dd1de374Slin wang - Sun Microsystems - Beijing China }
2849dd1de374Slin wang - Sun Microsystems - Beijing China 
2850dd1de374Slin wang - Sun Microsystems - Beijing China static void
2851dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_set_power_network_sleep(struct ath_hal *ah, int setChip)
2852dd1de374Slin wang - Sun Microsystems - Beijing China {
2853dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2854dd1de374Slin wang - Sun Microsystems - Beijing China 	if (setChip) {
2855dd1de374Slin wang - Sun Microsystems - Beijing China 		struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
2856dd1de374Slin wang - Sun Microsystems - Beijing China 
2857dd1de374Slin wang - Sun Microsystems - Beijing China 		if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
2858dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_WRITE(ah, AR_RTC_FORCE_WAKE,
2859dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR_RTC_FORCE_WAKE_ON_INT);
2860dd1de374Slin wang - Sun Microsystems - Beijing China 		} else {
2861dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2862dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR_RTC_FORCE_WAKE_EN);
2863dd1de374Slin wang - Sun Microsystems - Beijing China 		}
2864dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2865dd1de374Slin wang - Sun Microsystems - Beijing China }
2866dd1de374Slin wang - Sun Microsystems - Beijing China 
2867dd1de374Slin wang - Sun Microsystems - Beijing China static boolean_t
2868dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_set_power_awake(struct ath_hal *ah, int setChip)
2869dd1de374Slin wang - Sun Microsystems - Beijing China {
2870dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t val;
2871dd1de374Slin wang - Sun Microsystems - Beijing China 	int i;
2872dd1de374Slin wang - Sun Microsystems - Beijing China 
2873dd1de374Slin wang - Sun Microsystems - Beijing China 	if (setChip) {
2874dd1de374Slin wang - Sun Microsystems - Beijing China 		if ((REG_READ(ah, AR_RTC_STATUS) &
2875dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
2876dd1de374Slin wang - Sun Microsystems - Beijing China 			if (ath9k_hw_set_reset_reg(ah,
2877dd1de374Slin wang - Sun Microsystems - Beijing China 			    ATH9K_RESET_POWER_ON) != B_TRUE) {
2878dd1de374Slin wang - Sun Microsystems - Beijing China 				return (B_FALSE);
2879dd1de374Slin wang - Sun Microsystems - Beijing China 			}
2880dd1de374Slin wang - Sun Microsystems - Beijing China 		}
2881dd1de374Slin wang - Sun Microsystems - Beijing China 		if (AR_SREV_9100(ah))
2882dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_SET_BIT(ah, AR_RTC_RESET,
2883dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR_RTC_RESET_EN);
2884dd1de374Slin wang - Sun Microsystems - Beijing China 
2885dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2886dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_RTC_FORCE_WAKE_EN);
2887dd1de374Slin wang - Sun Microsystems - Beijing China 		drv_usecwait(50);
2888dd1de374Slin wang - Sun Microsystems - Beijing China 
2889dd1de374Slin wang - Sun Microsystems - Beijing China 		for (i = POWER_UP_TIME / 50; i > 0; i--) {
2890dd1de374Slin wang - Sun Microsystems - Beijing China 			val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
2891dd1de374Slin wang - Sun Microsystems - Beijing China 			if (val == AR_RTC_STATUS_ON)
2892dd1de374Slin wang - Sun Microsystems - Beijing China 				break;
2893dd1de374Slin wang - Sun Microsystems - Beijing China 			drv_usecwait(50);
2894dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2895dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR_RTC_FORCE_WAKE_EN);
2896dd1de374Slin wang - Sun Microsystems - Beijing China 		}
2897dd1de374Slin wang - Sun Microsystems - Beijing China 		if (i == 0) {
2898dd1de374Slin wang - Sun Microsystems - Beijing China 			ARN_DBG((ARN_DBG_POWER_MGMT,
2899dd1de374Slin wang - Sun Microsystems - Beijing China 			    "arn: ath9k_hw_set_power_awake(): "
2900dd1de374Slin wang - Sun Microsystems - Beijing China 			    "Failed to wakeup in %uus\n",
2901dd1de374Slin wang - Sun Microsystems - Beijing China 			    POWER_UP_TIME / 20));
2902dd1de374Slin wang - Sun Microsystems - Beijing China 
2903dd1de374Slin wang - Sun Microsystems - Beijing China 			return (B_FALSE);
2904dd1de374Slin wang - Sun Microsystems - Beijing China 		}
2905dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2906dd1de374Slin wang - Sun Microsystems - Beijing China 
2907dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2908dd1de374Slin wang - Sun Microsystems - Beijing China 
2909dd1de374Slin wang - Sun Microsystems - Beijing China 	return (B_TRUE);
2910dd1de374Slin wang - Sun Microsystems - Beijing China }
2911dd1de374Slin wang - Sun Microsystems - Beijing China 
2912dd1de374Slin wang - Sun Microsystems - Beijing China boolean_t
2913dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_setpower(struct ath_hal *ah, enum ath9k_power_mode mode)
2914dd1de374Slin wang - Sun Microsystems - Beijing China {
2915dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
2916dd1de374Slin wang - Sun Microsystems - Beijing China 	static const char *modes[] = {
2917dd1de374Slin wang - Sun Microsystems - Beijing China 		"AWAKE",
2918dd1de374Slin wang - Sun Microsystems - Beijing China 		"FULL-SLEEP",
2919dd1de374Slin wang - Sun Microsystems - Beijing China 		"NETWORK SLEEP",
2920dd1de374Slin wang - Sun Microsystems - Beijing China 		"UNDEFINED"
2921dd1de374Slin wang - Sun Microsystems - Beijing China 	};
2922dd1de374Slin wang - Sun Microsystems - Beijing China 	int status = B_TRUE, setChip = B_TRUE;
2923dd1de374Slin wang - Sun Microsystems - Beijing China 	ARN_DBG((ARN_DBG_ANY, "arn: ath9k_hw_setpower(): "
2924dd1de374Slin wang - Sun Microsystems - Beijing China 	    "%s -> %s (%s)\n",
2925dd1de374Slin wang - Sun Microsystems - Beijing China 	    modes[ahp->ah_powerMode],
2926dd1de374Slin wang - Sun Microsystems - Beijing China 	    modes[mode],
2927dd1de374Slin wang - Sun Microsystems - Beijing China 	    setChip ? "set chip " : ""));
2928dd1de374Slin wang - Sun Microsystems - Beijing China 
2929dd1de374Slin wang - Sun Microsystems - Beijing China 	switch (mode) {
2930dd1de374Slin wang - Sun Microsystems - Beijing China 	case ATH9K_PM_AWAKE:
2931dd1de374Slin wang - Sun Microsystems - Beijing China 		status = ath9k_hw_set_power_awake(ah, setChip);
2932dd1de374Slin wang - Sun Microsystems - Beijing China 		break;
2933dd1de374Slin wang - Sun Microsystems - Beijing China 	case ATH9K_PM_FULL_SLEEP:
2934dd1de374Slin wang - Sun Microsystems - Beijing China 		ath9k_set_power_sleep(ah, setChip);
2935dd1de374Slin wang - Sun Microsystems - Beijing China 		ahp->ah_chipFullSleep = B_TRUE;
2936dd1de374Slin wang - Sun Microsystems - Beijing China 		break;
2937dd1de374Slin wang - Sun Microsystems - Beijing China 	case ATH9K_PM_NETWORK_SLEEP:
2938dd1de374Slin wang - Sun Microsystems - Beijing China 		ath9k_set_power_network_sleep(ah, setChip);
2939dd1de374Slin wang - Sun Microsystems - Beijing China 		break;
2940dd1de374Slin wang - Sun Microsystems - Beijing China 	default:
2941dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_ANY, "arn: ath9k_hw_setpower(): "
2942dd1de374Slin wang - Sun Microsystems - Beijing China 		    "unknown power mode %u\n", mode));
2943dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_FALSE);
2944dd1de374Slin wang - Sun Microsystems - Beijing China 	}
2945dd1de374Slin wang - Sun Microsystems - Beijing China 	ahp->ah_powerMode = mode;
2946dd1de374Slin wang - Sun Microsystems - Beijing China 
2947dd1de374Slin wang - Sun Microsystems - Beijing China 	return (status);
2948dd1de374Slin wang - Sun Microsystems - Beijing China }
2949dd1de374Slin wang - Sun Microsystems - Beijing China 
2950dd1de374Slin wang - Sun Microsystems - Beijing China void
2951dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_configpcipowersave(struct ath_hal *ah, int restore)
2952dd1de374Slin wang - Sun Microsystems - Beijing China {
2953dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
2954dd1de374Slin wang - Sun Microsystems - Beijing China 	uint8_t i;
2955dd1de374Slin wang - Sun Microsystems - Beijing China 
2956dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ah->ah_isPciExpress != B_TRUE)
2957dd1de374Slin wang - Sun Microsystems - Beijing China 		return;
2958dd1de374Slin wang - Sun Microsystems - Beijing China 
2959dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ah->ah_config.pcie_powersave_enable == 2)
2960dd1de374Slin wang - Sun Microsystems - Beijing China 		return;
2961dd1de374Slin wang - Sun Microsystems - Beijing China 
2962dd1de374Slin wang - Sun Microsystems - Beijing China 	if (restore)
2963dd1de374Slin wang - Sun Microsystems - Beijing China 		return;
2964dd1de374Slin wang - Sun Microsystems - Beijing China 
2965dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9280_20_OR_LATER(ah)) {
2966dd1de374Slin wang - Sun Microsystems - Beijing China 		for (i = 0; i < ahp->ah_iniPcieSerdes.ia_rows; i++) {
2967dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_WRITE(ah, INI_RA(&ahp->ah_iniPcieSerdes, i, 0),
2968dd1de374Slin wang - Sun Microsystems - Beijing China 			    INI_RA(&ahp->ah_iniPcieSerdes, i, 1));
2969dd1de374Slin wang - Sun Microsystems - Beijing China 		}
2970dd1de374Slin wang - Sun Microsystems - Beijing China 		drv_usecwait(1000);
2971dd1de374Slin wang - Sun Microsystems - Beijing China 	} else if (AR_SREV_9280(ah) &&
2972dd1de374Slin wang - Sun Microsystems - Beijing China 	    (ah->ah_macRev == AR_SREV_REVISION_9280_10)) {
2973dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00);
2974dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
2975dd1de374Slin wang - Sun Microsystems - Beijing China 
2976dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019);
2977dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820);
2978dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560);
2979dd1de374Slin wang - Sun Microsystems - Beijing China 
2980dd1de374Slin wang - Sun Microsystems - Beijing China 		if (ah->ah_config.pcie_clock_req)
2981dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc);
2982dd1de374Slin wang - Sun Microsystems - Beijing China 		else
2983dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd);
2984dd1de374Slin wang - Sun Microsystems - Beijing China 
2985dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2986dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2987dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007);
2988dd1de374Slin wang - Sun Microsystems - Beijing China 
2989dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
2990dd1de374Slin wang - Sun Microsystems - Beijing China 
2991dd1de374Slin wang - Sun Microsystems - Beijing China 		drv_usecwait(1000);
2992dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
2993dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
2994dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
2995dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
2996dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
2997dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
2998dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
2999dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
3000dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
3001dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
3002dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
3003dd1de374Slin wang - Sun Microsystems - Beijing China 	}
3004dd1de374Slin wang - Sun Microsystems - Beijing China 
3005dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
3006dd1de374Slin wang - Sun Microsystems - Beijing China 
3007dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ah->ah_config.pcie_waen) {
3008dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_WA, ah->ah_config.pcie_waen);
3009dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
3010dd1de374Slin wang - Sun Microsystems - Beijing China 		if (AR_SREV_9285(ah))
3011dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_WRITE(ah, AR_WA, AR9285_WA_DEFAULT);
3012dd1de374Slin wang - Sun Microsystems - Beijing China 		else if (AR_SREV_9280(ah))
3013dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_WRITE(ah, AR_WA, AR9280_WA_DEFAULT);
3014dd1de374Slin wang - Sun Microsystems - Beijing China 		else
3015dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_WRITE(ah, AR_WA, AR_WA_DEFAULT);
3016dd1de374Slin wang - Sun Microsystems - Beijing China 	}
3017dd1de374Slin wang - Sun Microsystems - Beijing China }
3018dd1de374Slin wang - Sun Microsystems - Beijing China 
3019dd1de374Slin wang - Sun Microsystems - Beijing China /* Interrupt Handling */
3020dd1de374Slin wang - Sun Microsystems - Beijing China 
3021dd1de374Slin wang - Sun Microsystems - Beijing China boolean_t
3022dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_intrpend(struct ath_hal *ah)
3023dd1de374Slin wang - Sun Microsystems - Beijing China {
3024dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t host_isr;
3025dd1de374Slin wang - Sun Microsystems - Beijing China 
3026dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9100(ah))
3027dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_TRUE);
3028dd1de374Slin wang - Sun Microsystems - Beijing China 
3029dd1de374Slin wang - Sun Microsystems - Beijing China 	host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
3030dd1de374Slin wang - Sun Microsystems - Beijing China 	if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
3031dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_TRUE);
3032dd1de374Slin wang - Sun Microsystems - Beijing China 
3033dd1de374Slin wang - Sun Microsystems - Beijing China 	host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
3034dd1de374Slin wang - Sun Microsystems - Beijing China 
3035dd1de374Slin wang - Sun Microsystems - Beijing China 	if ((host_isr & AR_INTR_SYNC_DEFAULT) &&
3036dd1de374Slin wang - Sun Microsystems - Beijing China 	    (host_isr != AR_INTR_SPURIOUS))
3037dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_TRUE);
3038dd1de374Slin wang - Sun Microsystems - Beijing China 
3039dd1de374Slin wang - Sun Microsystems - Beijing China 	return (B_FALSE);
3040dd1de374Slin wang - Sun Microsystems - Beijing China }
3041dd1de374Slin wang - Sun Microsystems - Beijing China 
3042dd1de374Slin wang - Sun Microsystems - Beijing China boolean_t
3043dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_getisr(struct ath_hal *ah, enum ath9k_int *masked)
3044dd1de374Slin wang - Sun Microsystems - Beijing China {
3045dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t isr = 0;
3046dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t mask2 = 0;
3047dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
3048dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t sync_cause = 0;
3049dd1de374Slin wang - Sun Microsystems - Beijing China 	boolean_t fatal_int = B_FALSE;
3050dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
3051dd1de374Slin wang - Sun Microsystems - Beijing China 
3052dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!AR_SREV_9100(ah)) {
3053dd1de374Slin wang - Sun Microsystems - Beijing China 		if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
3054dd1de374Slin wang - Sun Microsystems - Beijing China 			if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
3055dd1de374Slin wang - Sun Microsystems - Beijing China 			    == AR_RTC_STATUS_ON) {
3056dd1de374Slin wang - Sun Microsystems - Beijing China 				isr = REG_READ(ah, AR_ISR);
3057dd1de374Slin wang - Sun Microsystems - Beijing China 			}
3058dd1de374Slin wang - Sun Microsystems - Beijing China 		}
3059dd1de374Slin wang - Sun Microsystems - Beijing China 
3060dd1de374Slin wang - Sun Microsystems - Beijing China 		sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
3061dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_INTR_SYNC_DEFAULT;
3062dd1de374Slin wang - Sun Microsystems - Beijing China 
3063dd1de374Slin wang - Sun Microsystems - Beijing China 		*masked = 0;
3064dd1de374Slin wang - Sun Microsystems - Beijing China 
3065dd1de374Slin wang - Sun Microsystems - Beijing China 		if (!isr && !sync_cause)
3066dd1de374Slin wang - Sun Microsystems - Beijing China 			return (B_FALSE);
3067dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
3068dd1de374Slin wang - Sun Microsystems - Beijing China 		*masked = 0;
3069dd1de374Slin wang - Sun Microsystems - Beijing China 		isr = REG_READ(ah, AR_ISR);
3070dd1de374Slin wang - Sun Microsystems - Beijing China 	}
3071dd1de374Slin wang - Sun Microsystems - Beijing China 
3072dd1de374Slin wang - Sun Microsystems - Beijing China 	if (isr) {
3073dd1de374Slin wang - Sun Microsystems - Beijing China 		if (isr & AR_ISR_BCNMISC) {
3074dd1de374Slin wang - Sun Microsystems - Beijing China 			uint32_t isr2;
3075dd1de374Slin wang - Sun Microsystems - Beijing China 			isr2 = REG_READ(ah, AR_ISR_S2);
3076dd1de374Slin wang - Sun Microsystems - Beijing China 			if (isr2 & AR_ISR_S2_TIM)
3077dd1de374Slin wang - Sun Microsystems - Beijing China 				mask2 |= ATH9K_INT_TIM;
3078dd1de374Slin wang - Sun Microsystems - Beijing China 			if (isr2 & AR_ISR_S2_DTIM)
3079dd1de374Slin wang - Sun Microsystems - Beijing China 				mask2 |= ATH9K_INT_DTIM;
3080dd1de374Slin wang - Sun Microsystems - Beijing China 			if (isr2 & AR_ISR_S2_DTIMSYNC)
3081dd1de374Slin wang - Sun Microsystems - Beijing China 				mask2 |= ATH9K_INT_DTIMSYNC;
3082dd1de374Slin wang - Sun Microsystems - Beijing China 			if (isr2 & (AR_ISR_S2_CABEND))
3083dd1de374Slin wang - Sun Microsystems - Beijing China 				mask2 |= ATH9K_INT_CABEND;
3084dd1de374Slin wang - Sun Microsystems - Beijing China 			if (isr2 & AR_ISR_S2_GTT)
3085dd1de374Slin wang - Sun Microsystems - Beijing China 				mask2 |= ATH9K_INT_GTT;
3086dd1de374Slin wang - Sun Microsystems - Beijing China 			if (isr2 & AR_ISR_S2_CST)
3087dd1de374Slin wang - Sun Microsystems - Beijing China 				mask2 |= ATH9K_INT_CST;
3088dd1de374Slin wang - Sun Microsystems - Beijing China 		}
3089dd1de374Slin wang - Sun Microsystems - Beijing China 
3090dd1de374Slin wang - Sun Microsystems - Beijing China 		isr = REG_READ(ah, AR_ISR_RAC);
3091dd1de374Slin wang - Sun Microsystems - Beijing China 		if (isr == 0xffffffff) {
3092dd1de374Slin wang - Sun Microsystems - Beijing China 			*masked = 0;
3093dd1de374Slin wang - Sun Microsystems - Beijing China 			return (B_FALSE);
3094dd1de374Slin wang - Sun Microsystems - Beijing China 		}
3095dd1de374Slin wang - Sun Microsystems - Beijing China 
3096dd1de374Slin wang - Sun Microsystems - Beijing China 		*masked = isr & ATH9K_INT_COMMON;
3097dd1de374Slin wang - Sun Microsystems - Beijing China 
3098dd1de374Slin wang - Sun Microsystems - Beijing China 		if (ahp->ah_intrMitigation) {
3099dd1de374Slin wang - Sun Microsystems - Beijing China 			if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
3100dd1de374Slin wang - Sun Microsystems - Beijing China 				*masked |= ATH9K_INT_RX;
3101dd1de374Slin wang - Sun Microsystems - Beijing China 		}
3102dd1de374Slin wang - Sun Microsystems - Beijing China 
3103dd1de374Slin wang - Sun Microsystems - Beijing China 		if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
3104dd1de374Slin wang - Sun Microsystems - Beijing China 			*masked |= ATH9K_INT_RX;
3105dd1de374Slin wang - Sun Microsystems - Beijing China 		if (isr &
3106dd1de374Slin wang - Sun Microsystems - Beijing China 		    (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
3107dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_ISR_TXEOL)) {
3108dd1de374Slin wang - Sun Microsystems - Beijing China 			uint32_t s0_s, s1_s;
3109dd1de374Slin wang - Sun Microsystems - Beijing China 
3110dd1de374Slin wang - Sun Microsystems - Beijing China 			*masked |= ATH9K_INT_TX;
3111dd1de374Slin wang - Sun Microsystems - Beijing China 
3112dd1de374Slin wang - Sun Microsystems - Beijing China 			s0_s = REG_READ(ah, AR_ISR_S0_S);
3113dd1de374Slin wang - Sun Microsystems - Beijing China 			ahp->ah_intrTxqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
3114dd1de374Slin wang - Sun Microsystems - Beijing China 			ahp->ah_intrTxqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
3115dd1de374Slin wang - Sun Microsystems - Beijing China 
3116dd1de374Slin wang - Sun Microsystems - Beijing China 			s1_s = REG_READ(ah, AR_ISR_S1_S);
3117dd1de374Slin wang - Sun Microsystems - Beijing China 			ahp->ah_intrTxqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
3118dd1de374Slin wang - Sun Microsystems - Beijing China 			ahp->ah_intrTxqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
3119dd1de374Slin wang - Sun Microsystems - Beijing China 		}
3120dd1de374Slin wang - Sun Microsystems - Beijing China 
3121dd1de374Slin wang - Sun Microsystems - Beijing China 		if (isr & AR_ISR_RXORN) {
3122dd1de374Slin wang - Sun Microsystems - Beijing China 			ARN_DBG((ARN_DBG_INTERRUPT, "arn: "
3123dd1de374Slin wang - Sun Microsystems - Beijing China 			    "%s: receive FIFO overrun interrupt\n", __func__));
3124dd1de374Slin wang - Sun Microsystems - Beijing China 		}
3125dd1de374Slin wang - Sun Microsystems - Beijing China 
3126dd1de374Slin wang - Sun Microsystems - Beijing China 		if (!AR_SREV_9100(ah)) {
3127dd1de374Slin wang - Sun Microsystems - Beijing China 			if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
3128dd1de374Slin wang - Sun Microsystems - Beijing China 				uint32_t isr5 = REG_READ(ah, AR_ISR_S5_S);
3129dd1de374Slin wang - Sun Microsystems - Beijing China 				if (isr5 & AR_ISR_S5_TIM_TIMER)
3130dd1de374Slin wang - Sun Microsystems - Beijing China 					*masked |= ATH9K_INT_TIM_TIMER;
3131dd1de374Slin wang - Sun Microsystems - Beijing China 			}
3132dd1de374Slin wang - Sun Microsystems - Beijing China 		}
3133dd1de374Slin wang - Sun Microsystems - Beijing China 
3134dd1de374Slin wang - Sun Microsystems - Beijing China 		*masked |= mask2;
3135dd1de374Slin wang - Sun Microsystems - Beijing China 	}
3136dd1de374Slin wang - Sun Microsystems - Beijing China 
3137dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9100(ah))
3138dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_TRUE);
3139dd1de374Slin wang - Sun Microsystems - Beijing China 
3140dd1de374Slin wang - Sun Microsystems - Beijing China 	if (sync_cause) {
3141dd1de374Slin wang - Sun Microsystems - Beijing China 		fatal_int = (sync_cause &
3142dd1de374Slin wang - Sun Microsystems - Beijing China 		    (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR)) ?
3143dd1de374Slin wang - Sun Microsystems - Beijing China 		    B_TRUE : B_FALSE;
3144dd1de374Slin wang - Sun Microsystems - Beijing China 
3145dd1de374Slin wang - Sun Microsystems - Beijing China 		if (fatal_int) {
3146dd1de374Slin wang - Sun Microsystems - Beijing China 			if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
3147dd1de374Slin wang - Sun Microsystems - Beijing China 				ARN_DBG((ARN_DBG_INTERRUPT, "arn: "
3148dd1de374Slin wang - Sun Microsystems - Beijing China 				    "%s: received PCI FATAL interrupt\n",
3149dd1de374Slin wang - Sun Microsystems - Beijing China 				    __func__));
3150dd1de374Slin wang - Sun Microsystems - Beijing China 			}
3151dd1de374Slin wang - Sun Microsystems - Beijing China 			if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
3152dd1de374Slin wang - Sun Microsystems - Beijing China 				ARN_DBG((ARN_DBG_INTERRUPT, "arn: "
3153dd1de374Slin wang - Sun Microsystems - Beijing China 				    "%s: received PCI PERR interrupt\n",
3154dd1de374Slin wang - Sun Microsystems - Beijing China 				    __func__));
3155dd1de374Slin wang - Sun Microsystems - Beijing China 			}
3156dd1de374Slin wang - Sun Microsystems - Beijing China 		}
3157dd1de374Slin wang - Sun Microsystems - Beijing China 		if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
3158dd1de374Slin wang - Sun Microsystems - Beijing China 			ARN_DBG((ARN_DBG_INTERRUPT, "arn: "
3159dd1de374Slin wang - Sun Microsystems - Beijing China 			    "%s: AR_INTR_SYNC_RADM_CPL_TIMEOUT\n",
3160dd1de374Slin wang - Sun Microsystems - Beijing China 			    __func__));
3161dd1de374Slin wang - Sun Microsystems - Beijing China 
3162dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
3163dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_WRITE(ah, AR_RC, 0);
3164dd1de374Slin wang - Sun Microsystems - Beijing China 			*masked |= ATH9K_INT_FATAL;
3165dd1de374Slin wang - Sun Microsystems - Beijing China 		}
3166dd1de374Slin wang - Sun Microsystems - Beijing China 		if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
3167dd1de374Slin wang - Sun Microsystems - Beijing China 			ARN_DBG((ARN_DBG_ANY, "arn: "
3168dd1de374Slin wang - Sun Microsystems - Beijing China 			    "%s: AR_INTR_SYNC_LOCAL_TIMEOUT\n",
3169dd1de374Slin wang - Sun Microsystems - Beijing China 			    __func__));
3170dd1de374Slin wang - Sun Microsystems - Beijing China 		}
3171dd1de374Slin wang - Sun Microsystems - Beijing China 
3172dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
3173dd1de374Slin wang - Sun Microsystems - Beijing China 		(void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
3174dd1de374Slin wang - Sun Microsystems - Beijing China 	}
3175dd1de374Slin wang - Sun Microsystems - Beijing China 
3176dd1de374Slin wang - Sun Microsystems - Beijing China 	return (B_TRUE);
3177dd1de374Slin wang - Sun Microsystems - Beijing China }
3178dd1de374Slin wang - Sun Microsystems - Beijing China 
3179dd1de374Slin wang - Sun Microsystems - Beijing China enum ath9k_int
3180dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_intrget(struct ath_hal *ah)
3181dd1de374Slin wang - Sun Microsystems - Beijing China {
3182dd1de374Slin wang - Sun Microsystems - Beijing China 	return (AH5416(ah)->ah_maskReg);
3183dd1de374Slin wang - Sun Microsystems - Beijing China }
3184dd1de374Slin wang - Sun Microsystems - Beijing China 
3185dd1de374Slin wang - Sun Microsystems - Beijing China enum ath9k_int
3186dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_set_interrupts(struct ath_hal *ah, enum ath9k_int ints)
3187dd1de374Slin wang - Sun Microsystems - Beijing China {
3188dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
3189dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t omask = ahp->ah_maskReg;
3190dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t mask, mask2;
3191dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
3192dd1de374Slin wang - Sun Microsystems - Beijing China 
3193dd1de374Slin wang - Sun Microsystems - Beijing China 	ARN_DBG((ARN_DBG_INTERRUPT,
3194dd1de374Slin wang - Sun Microsystems - Beijing China 	    "arn: ath9k_hw_set_interrupts(): "
3195dd1de374Slin wang - Sun Microsystems - Beijing China 	    "0x%x => 0x%x\n", omask, ints));
3196dd1de374Slin wang - Sun Microsystems - Beijing China 
3197dd1de374Slin wang - Sun Microsystems - Beijing China 	if (omask & ATH9K_INT_GLOBAL) {
3198dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_INTERRUPT,
3199dd1de374Slin wang - Sun Microsystems - Beijing China 		    "arn: ath9k_hw_set_interrupts(): "
3200dd1de374Slin wang - Sun Microsystems - Beijing China 		    "disable IER\n"));
3201dd1de374Slin wang - Sun Microsystems - Beijing China 
3202dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
3203dd1de374Slin wang - Sun Microsystems - Beijing China 		(void) REG_READ(ah, AR_IER);
3204dd1de374Slin wang - Sun Microsystems - Beijing China 		if (!AR_SREV_9100(ah)) {
3205dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
3206dd1de374Slin wang - Sun Microsystems - Beijing China 			(void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
3207dd1de374Slin wang - Sun Microsystems - Beijing China 
3208dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
3209dd1de374Slin wang - Sun Microsystems - Beijing China 			(void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
3210dd1de374Slin wang - Sun Microsystems - Beijing China 		}
3211dd1de374Slin wang - Sun Microsystems - Beijing China 	}
3212dd1de374Slin wang - Sun Microsystems - Beijing China 
3213dd1de374Slin wang - Sun Microsystems - Beijing China 	mask = ints & ATH9K_INT_COMMON;
3214dd1de374Slin wang - Sun Microsystems - Beijing China 	mask2 = 0;
3215dd1de374Slin wang - Sun Microsystems - Beijing China 
3216dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ints & ATH9K_INT_TX) {
3217dd1de374Slin wang - Sun Microsystems - Beijing China 		if (ahp->ah_txOkInterruptMask)
3218dd1de374Slin wang - Sun Microsystems - Beijing China 			mask |= AR_IMR_TXOK;
3219dd1de374Slin wang - Sun Microsystems - Beijing China 		if (ahp->ah_txDescInterruptMask)
3220dd1de374Slin wang - Sun Microsystems - Beijing China 			mask |= AR_IMR_TXDESC;
3221dd1de374Slin wang - Sun Microsystems - Beijing China 		if (ahp->ah_txErrInterruptMask)
3222dd1de374Slin wang - Sun Microsystems - Beijing China 			mask |= AR_IMR_TXERR;
3223dd1de374Slin wang - Sun Microsystems - Beijing China 		if (ahp->ah_txEolInterruptMask)
3224dd1de374Slin wang - Sun Microsystems - Beijing China 			mask |= AR_IMR_TXEOL;
3225dd1de374Slin wang - Sun Microsystems - Beijing China 	}
3226dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ints & ATH9K_INT_RX) {
3227dd1de374Slin wang - Sun Microsystems - Beijing China 		mask |= AR_IMR_RXERR;
3228dd1de374Slin wang - Sun Microsystems - Beijing China 		if (ahp->ah_intrMitigation)
3229dd1de374Slin wang - Sun Microsystems - Beijing China 			mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
3230dd1de374Slin wang - Sun Microsystems - Beijing China 		else
3231dd1de374Slin wang - Sun Microsystems - Beijing China 			mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
3232dd1de374Slin wang - Sun Microsystems - Beijing China 		if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
3233dd1de374Slin wang - Sun Microsystems - Beijing China 			mask |= AR_IMR_GENTMR;
3234dd1de374Slin wang - Sun Microsystems - Beijing China 	}
3235dd1de374Slin wang - Sun Microsystems - Beijing China 
3236dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ints & (ATH9K_INT_BMISC)) {
3237dd1de374Slin wang - Sun Microsystems - Beijing China 		mask |= AR_IMR_BCNMISC;
3238dd1de374Slin wang - Sun Microsystems - Beijing China 		if (ints & ATH9K_INT_TIM)
3239dd1de374Slin wang - Sun Microsystems - Beijing China 			mask2 |= AR_IMR_S2_TIM;
3240dd1de374Slin wang - Sun Microsystems - Beijing China 		if (ints & ATH9K_INT_DTIM)
3241dd1de374Slin wang - Sun Microsystems - Beijing China 			mask2 |= AR_IMR_S2_DTIM;
3242dd1de374Slin wang - Sun Microsystems - Beijing China 		if (ints & ATH9K_INT_DTIMSYNC)
3243dd1de374Slin wang - Sun Microsystems - Beijing China 			mask2 |= AR_IMR_S2_DTIMSYNC;
3244dd1de374Slin wang - Sun Microsystems - Beijing China 		if (ints & ATH9K_INT_CABEND)
3245dd1de374Slin wang - Sun Microsystems - Beijing China 			mask2 |= (AR_IMR_S2_CABEND);
3246dd1de374Slin wang - Sun Microsystems - Beijing China 	}
3247dd1de374Slin wang - Sun Microsystems - Beijing China 
3248dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
3249dd1de374Slin wang - Sun Microsystems - Beijing China 		mask |= AR_IMR_BCNMISC;
3250dd1de374Slin wang - Sun Microsystems - Beijing China 		if (ints & ATH9K_INT_GTT)
3251dd1de374Slin wang - Sun Microsystems - Beijing China 			mask2 |= AR_IMR_S2_GTT;
3252dd1de374Slin wang - Sun Microsystems - Beijing China 		if (ints & ATH9K_INT_CST)
3253dd1de374Slin wang - Sun Microsystems - Beijing China 			mask2 |= AR_IMR_S2_CST;
3254dd1de374Slin wang - Sun Microsystems - Beijing China 	}
3255dd1de374Slin wang - Sun Microsystems - Beijing China 
3256dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_IMR, mask);
3257dd1de374Slin wang - Sun Microsystems - Beijing China 	mask = REG_READ(ah, AR_IMR_S2) &
3258dd1de374Slin wang - Sun Microsystems - Beijing China 	    ~(AR_IMR_S2_TIM |
3259dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_IMR_S2_DTIM |
3260dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_IMR_S2_DTIMSYNC |
3261dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_IMR_S2_CABEND |
3262dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_IMR_S2_CABTO |
3263dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_IMR_S2_TSFOOR |
3264dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_IMR_S2_GTT |
3265dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_IMR_S2_CST);
3266dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_IMR_S2, mask | mask2);
3267dd1de374Slin wang - Sun Microsystems - Beijing China 	ahp->ah_maskReg = ints;
3268dd1de374Slin wang - Sun Microsystems - Beijing China 
3269dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
3270dd1de374Slin wang - Sun Microsystems - Beijing China 		if (ints & ATH9K_INT_TIM_TIMER)
3271dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
3272dd1de374Slin wang - Sun Microsystems - Beijing China 		else
3273dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
3274dd1de374Slin wang - Sun Microsystems - Beijing China 	}
3275dd1de374Slin wang - Sun Microsystems - Beijing China 
3276dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ints & ATH9K_INT_GLOBAL) {
3277dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
3278dd1de374Slin wang - Sun Microsystems - Beijing China 		if (!AR_SREV_9100(ah)) {
3279dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
3280dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR_INTR_MAC_IRQ);
3281dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
3282dd1de374Slin wang - Sun Microsystems - Beijing China 
3283dd1de374Slin wang - Sun Microsystems - Beijing China 
3284dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_WRITE(ah, AR_INTR_SYNC_ENABLE,
3285dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR_INTR_SYNC_DEFAULT);
3286dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_WRITE(ah, AR_INTR_SYNC_MASK,
3287dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR_INTR_SYNC_DEFAULT);
3288dd1de374Slin wang - Sun Microsystems - Beijing China 		}
3289dd1de374Slin wang - Sun Microsystems - Beijing China 
3290dd1de374Slin wang - Sun Microsystems - Beijing China 	}
3291dd1de374Slin wang - Sun Microsystems - Beijing China 
3292dd1de374Slin wang - Sun Microsystems - Beijing China 	return (omask);
3293dd1de374Slin wang - Sun Microsystems - Beijing China }
3294dd1de374Slin wang - Sun Microsystems - Beijing China 
3295dd1de374Slin wang - Sun Microsystems - Beijing China /* Beacon Handling */
3296dd1de374Slin wang - Sun Microsystems - Beijing China 
3297dd1de374Slin wang - Sun Microsystems - Beijing China void
3298dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_beaconinit(struct ath_hal *ah, uint32_t next_beacon,
3299dd1de374Slin wang - Sun Microsystems - Beijing China     uint32_t beacon_period)
3300dd1de374Slin wang - Sun Microsystems - Beijing China {
3301dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
3302dd1de374Slin wang - Sun Microsystems - Beijing China 	int flags = 0;
3303dd1de374Slin wang - Sun Microsystems - Beijing China 
3304dd1de374Slin wang - Sun Microsystems - Beijing China 	ahp->ah_beaconInterval = beacon_period;
3305dd1de374Slin wang - Sun Microsystems - Beijing China 
3306dd1de374Slin wang - Sun Microsystems - Beijing China 	switch (ah->ah_opmode) {
3307dd1de374Slin wang - Sun Microsystems - Beijing China 	case ATH9K_M_STA:
3308dd1de374Slin wang - Sun Microsystems - Beijing China 	case ATH9K_M_MONITOR:
3309dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
3310dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
3311dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
3312dd1de374Slin wang - Sun Microsystems - Beijing China 		flags |= AR_TBTT_TIMER_EN;
3313dd1de374Slin wang - Sun Microsystems - Beijing China 		break;
3314dd1de374Slin wang - Sun Microsystems - Beijing China 	case ATH9K_M_IBSS:
3315dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_SET_BIT(ah, AR_TXCFG,
3316dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
3317dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_NEXT_NDP_TIMER,
3318dd1de374Slin wang - Sun Microsystems - Beijing China 		    TU_TO_USEC(next_beacon +
3319dd1de374Slin wang - Sun Microsystems - Beijing China 		    (ahp->ah_atimWindow ? ahp->
3320dd1de374Slin wang - Sun Microsystems - Beijing China 		    ah_atimWindow : 1)));
3321dd1de374Slin wang - Sun Microsystems - Beijing China 		flags |= AR_NDP_TIMER_EN;
3322dd1de374Slin wang - Sun Microsystems - Beijing China 		/*FALLTHRU*/
3323dd1de374Slin wang - Sun Microsystems - Beijing China 	case ATH9K_M_HOSTAP:
3324dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
3325dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT,
3326dd1de374Slin wang - Sun Microsystems - Beijing China 		    TU_TO_USEC(next_beacon -
3327dd1de374Slin wang - Sun Microsystems - Beijing China 		    ah->ah_config.
3328dd1de374Slin wang - Sun Microsystems - Beijing China 		    dma_beacon_response_time));
3329dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_NEXT_SWBA,
3330dd1de374Slin wang - Sun Microsystems - Beijing China 		    TU_TO_USEC(next_beacon -
3331dd1de374Slin wang - Sun Microsystems - Beijing China 		    ah->ah_config.
3332dd1de374Slin wang - Sun Microsystems - Beijing China 		    sw_beacon_response_time));
3333dd1de374Slin wang - Sun Microsystems - Beijing China 		flags |=
3334dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
3335dd1de374Slin wang - Sun Microsystems - Beijing China 		break;
3336dd1de374Slin wang - Sun Microsystems - Beijing China 	default:
3337dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_BEACON,
3338dd1de374Slin wang - Sun Microsystems - Beijing China 		    "%s: unsupported opmode: %d\n",
3339dd1de374Slin wang - Sun Microsystems - Beijing China 		    __func__, ah->ah_opmode));
3340dd1de374Slin wang - Sun Microsystems - Beijing China 		return;
3341dd1de374Slin wang - Sun Microsystems - Beijing China 	}
3342dd1de374Slin wang - Sun Microsystems - Beijing China 
3343dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3344dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3345dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period));
3346dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period));
3347dd1de374Slin wang - Sun Microsystems - Beijing China 
3348dd1de374Slin wang - Sun Microsystems - Beijing China 	beacon_period &= ~ATH9K_BEACON_ENA;
3349dd1de374Slin wang - Sun Microsystems - Beijing China 	if (beacon_period & ATH9K_BEACON_RESET_TSF) {
3350dd1de374Slin wang - Sun Microsystems - Beijing China 		beacon_period &= ~ATH9K_BEACON_RESET_TSF;
3351dd1de374Slin wang - Sun Microsystems - Beijing China 		ath9k_hw_reset_tsf(ah);
3352dd1de374Slin wang - Sun Microsystems - Beijing China 	}
3353dd1de374Slin wang - Sun Microsystems - Beijing China 
3354dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_SET_BIT(ah, AR_TIMER_MODE, flags);
3355dd1de374Slin wang - Sun Microsystems - Beijing China }
3356dd1de374Slin wang - Sun Microsystems - Beijing China 
3357dd1de374Slin wang - Sun Microsystems - Beijing China void
3358dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_set_sta_beacon_timers(struct ath_hal *ah,
3359dd1de374Slin wang - Sun Microsystems - Beijing China     const struct ath9k_beacon_state *bs)
3360dd1de374Slin wang - Sun Microsystems - Beijing China {
3361dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t nextTbtt, beaconintval, dtimperiod, beacontimeout;
3362dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
3363dd1de374Slin wang - Sun Microsystems - Beijing China 
3364dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
3365dd1de374Slin wang - Sun Microsystems - Beijing China 
3366dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_BEACON_PERIOD,
3367dd1de374Slin wang - Sun Microsystems - Beijing China 	    TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3368dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
3369dd1de374Slin wang - Sun Microsystems - Beijing China 	    TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3370dd1de374Slin wang - Sun Microsystems - Beijing China 
3371dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_RMW_FIELD(ah, AR_RSSI_THR,
3372dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
3373dd1de374Slin wang - Sun Microsystems - Beijing China 
3374dd1de374Slin wang - Sun Microsystems - Beijing China 	beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD;
3375dd1de374Slin wang - Sun Microsystems - Beijing China 
3376dd1de374Slin wang - Sun Microsystems - Beijing China 	if (bs->bs_sleepduration > beaconintval)
3377dd1de374Slin wang - Sun Microsystems - Beijing China 		beaconintval = bs->bs_sleepduration;
3378dd1de374Slin wang - Sun Microsystems - Beijing China 
3379dd1de374Slin wang - Sun Microsystems - Beijing China 	dtimperiod = bs->bs_dtimperiod;
3380dd1de374Slin wang - Sun Microsystems - Beijing China 	if (bs->bs_sleepduration > dtimperiod)
3381dd1de374Slin wang - Sun Microsystems - Beijing China 		dtimperiod = bs->bs_sleepduration;
3382dd1de374Slin wang - Sun Microsystems - Beijing China 
3383dd1de374Slin wang - Sun Microsystems - Beijing China 	if (beaconintval == dtimperiod)
3384dd1de374Slin wang - Sun Microsystems - Beijing China 		nextTbtt = bs->bs_nextdtim;
3385dd1de374Slin wang - Sun Microsystems - Beijing China 	else
3386dd1de374Slin wang - Sun Microsystems - Beijing China 		nextTbtt = bs->bs_nexttbtt;
3387dd1de374Slin wang - Sun Microsystems - Beijing China 
3388dd1de374Slin wang - Sun Microsystems - Beijing China 	ARN_DBG((ARN_DBG_BEACON, "arn: "
3389dd1de374Slin wang - Sun Microsystems - Beijing China 	    "%s: next DTIM %d\n", __func__, bs->bs_nextdtim));
3390dd1de374Slin wang - Sun Microsystems - Beijing China 	ARN_DBG((ARN_DBG_BEACON, "arn: "
3391dd1de374Slin wang - Sun Microsystems - Beijing China 	    "%s: next beacon %d\n", __func__, nextTbtt));
3392dd1de374Slin wang - Sun Microsystems - Beijing China 	ARN_DBG((ARN_DBG_BEACON, "arn: "
3393dd1de374Slin wang - Sun Microsystems - Beijing China 	    "%s: beacon period %d\n", __func__, beaconintval));
3394dd1de374Slin wang - Sun Microsystems - Beijing China 	ARN_DBG((ARN_DBG_BEACON, "arn: "
3395dd1de374Slin wang - Sun Microsystems - Beijing China 	    "%s: DTIM period %d\n", __func__, dtimperiod));
3396dd1de374Slin wang - Sun Microsystems - Beijing China 
3397dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_NEXT_DTIM,
3398dd1de374Slin wang - Sun Microsystems - Beijing China 	    TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
3399dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
3400dd1de374Slin wang - Sun Microsystems - Beijing China 
3401dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_SLEEP1,
3402dd1de374Slin wang - Sun Microsystems - Beijing China 	    SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT) |
3403dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_SLEEP1_ASSUME_DTIM);
3404dd1de374Slin wang - Sun Microsystems - Beijing China 
3405dd1de374Slin wang - Sun Microsystems - Beijing China 	if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
3406dd1de374Slin wang - Sun Microsystems - Beijing China 		beacontimeout = (BEACON_TIMEOUT_VAL << 3);
3407dd1de374Slin wang - Sun Microsystems - Beijing China 	else
3408dd1de374Slin wang - Sun Microsystems - Beijing China 		beacontimeout = MIN_BEACON_TIMEOUT_VAL;
3409dd1de374Slin wang - Sun Microsystems - Beijing China 
3410dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_SLEEP2,
3411dd1de374Slin wang - Sun Microsystems - Beijing China 	    SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
3412dd1de374Slin wang - Sun Microsystems - Beijing China 
3413dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
3414dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
3415dd1de374Slin wang - Sun Microsystems - Beijing China 
3416dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_SET_BIT(ah, AR_TIMER_MODE,
3417dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_TBTT_TIMER_EN |
3418dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_TIM_TIMER_EN |
3419dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_DTIM_TIMER_EN);
3420dd1de374Slin wang - Sun Microsystems - Beijing China 
34213ae945c3Slin wang - Sun Microsystems - Beijing China 	/* TSF Out of Range Threshold */
34223ae945c3Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
3423dd1de374Slin wang - Sun Microsystems - Beijing China }
3424dd1de374Slin wang - Sun Microsystems - Beijing China 
3425dd1de374Slin wang - Sun Microsystems - Beijing China /* HW Capabilities */
3426dd1de374Slin wang - Sun Microsystems - Beijing China 
3427dd1de374Slin wang - Sun Microsystems - Beijing China boolean_t
3428dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_fill_cap_info(struct ath_hal *ah)
3429dd1de374Slin wang - Sun Microsystems - Beijing China {
3430dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
3431dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
3432dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t capField = 0, eeval;
3433dd1de374Slin wang - Sun Microsystems - Beijing China 
3434dd1de374Slin wang - Sun Microsystems - Beijing China 	eeval = ath9k_hw_get_eeprom(ah, EEP_REG_0);
3435dd1de374Slin wang - Sun Microsystems - Beijing China 
3436dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_currentRD = eeval;
3437dd1de374Slin wang - Sun Microsystems - Beijing China 
3438dd1de374Slin wang - Sun Microsystems - Beijing China 	eeval = ath9k_hw_get_eeprom(ah, EEP_REG_1);
3439dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_currentRDExt = eeval;
3440dd1de374Slin wang - Sun Microsystems - Beijing China 
3441dd1de374Slin wang - Sun Microsystems - Beijing China 	capField = ath9k_hw_get_eeprom(ah, EEP_OP_CAP);
3442dd1de374Slin wang - Sun Microsystems - Beijing China 
3443dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ah->ah_opmode != ATH9K_M_HOSTAP &&
3444dd1de374Slin wang - Sun Microsystems - Beijing China 	    ah->ah_subvendorid == AR_SUBVENDOR_ID_NEW_A) {
3445dd1de374Slin wang - Sun Microsystems - Beijing China 		if (ah->ah_currentRD == 0x64 ||
3446dd1de374Slin wang - Sun Microsystems - Beijing China 		    ah->ah_currentRD == 0x65)
3447dd1de374Slin wang - Sun Microsystems - Beijing China 			ah->ah_currentRD += 5;
3448dd1de374Slin wang - Sun Microsystems - Beijing China 		else if (ah->ah_currentRD == 0x41)
3449dd1de374Slin wang - Sun Microsystems - Beijing China 			ah->ah_currentRD = 0x43;
3450dd1de374Slin wang - Sun Microsystems - Beijing China 
3451dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_REGULATORY,
3452dd1de374Slin wang - Sun Microsystems - Beijing China 		    "%s: regdomain mapped to 0x%x\n", __func__,
3453dd1de374Slin wang - Sun Microsystems - Beijing China 		    ah->ah_currentRD));
3454dd1de374Slin wang - Sun Microsystems - Beijing China 	}
3455dd1de374Slin wang - Sun Microsystems - Beijing China 
3456dd1de374Slin wang - Sun Microsystems - Beijing China 	eeval = ath9k_hw_get_eeprom(ah, EEP_OP_MODE);
3457dd1de374Slin wang - Sun Microsystems - Beijing China 
3458dd1de374Slin wang - Sun Microsystems - Beijing China 	bzero(pCap->wireless_modes, sizeof (uint8_t)*4);
3459dd1de374Slin wang - Sun Microsystems - Beijing China 
3460dd1de374Slin wang - Sun Microsystems - Beijing China 	if (eeval & AR5416_OPFLAGS_11A) {
3461dd1de374Slin wang - Sun Microsystems - Beijing China 		set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
3462dd1de374Slin wang - Sun Microsystems - Beijing China 		if (ah->ah_config.ht_enable) {
3463dd1de374Slin wang - Sun Microsystems - Beijing China 			if (!(eeval & AR5416_OPFLAGS_N_5G_HT20))
3464dd1de374Slin wang - Sun Microsystems - Beijing China 				set_bit(ATH9K_MODE_11NA_HT20,
3465dd1de374Slin wang - Sun Microsystems - Beijing China 				    pCap->wireless_modes);
3466dd1de374Slin wang - Sun Microsystems - Beijing China 			if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) {
3467dd1de374Slin wang - Sun Microsystems - Beijing China 				set_bit(ATH9K_MODE_11NA_HT40PLUS,
3468dd1de374Slin wang - Sun Microsystems - Beijing China 				    pCap->wireless_modes);
3469dd1de374Slin wang - Sun Microsystems - Beijing China 				set_bit(ATH9K_MODE_11NA_HT40MINUS,
3470dd1de374Slin wang - Sun Microsystems - Beijing China 				    pCap->wireless_modes);
3471dd1de374Slin wang - Sun Microsystems - Beijing China 			}
3472dd1de374Slin wang - Sun Microsystems - Beijing China 		}
3473dd1de374Slin wang - Sun Microsystems - Beijing China 	}
3474dd1de374Slin wang - Sun Microsystems - Beijing China 
3475dd1de374Slin wang - Sun Microsystems - Beijing China 	if (eeval & AR5416_OPFLAGS_11G) {
3476dd1de374Slin wang - Sun Microsystems - Beijing China 		set_bit(ATH9K_MODE_11B, pCap->wireless_modes);
3477dd1de374Slin wang - Sun Microsystems - Beijing China 		set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
3478dd1de374Slin wang - Sun Microsystems - Beijing China 		if (ah->ah_config.ht_enable) {
3479dd1de374Slin wang - Sun Microsystems - Beijing China 			if (!(eeval & AR5416_OPFLAGS_N_2G_HT20))
3480dd1de374Slin wang - Sun Microsystems - Beijing China 				set_bit(ATH9K_MODE_11NG_HT20,
3481dd1de374Slin wang - Sun Microsystems - Beijing China 				    pCap->wireless_modes);
3482dd1de374Slin wang - Sun Microsystems - Beijing China 			if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) {
3483dd1de374Slin wang - Sun Microsystems - Beijing China 				set_bit(ATH9K_MODE_11NG_HT40PLUS,
3484dd1de374Slin wang - Sun Microsystems - Beijing China 				    pCap->wireless_modes);
3485dd1de374Slin wang - Sun Microsystems - Beijing China 				set_bit(ATH9K_MODE_11NG_HT40MINUS,
3486dd1de374Slin wang - Sun Microsystems - Beijing China 				    pCap->wireless_modes);
3487dd1de374Slin wang - Sun Microsystems - Beijing China 			}
3488dd1de374Slin wang - Sun Microsystems - Beijing China 		}
3489dd1de374Slin wang - Sun Microsystems - Beijing China 	}
3490dd1de374Slin wang - Sun Microsystems - Beijing China 
3491dd1de374Slin wang - Sun Microsystems - Beijing China 	pCap->tx_chainmask = ath9k_hw_get_eeprom(ah, EEP_TX_MASK);
3492dd1de374Slin wang - Sun Microsystems - Beijing China 	if ((ah->ah_isPciExpress) ||
3493dd1de374Slin wang - Sun Microsystems - Beijing China 	    (eeval & AR5416_OPFLAGS_11A)) {
3494dd1de374Slin wang - Sun Microsystems - Beijing China 		pCap->rx_chainmask =
3495dd1de374Slin wang - Sun Microsystems - Beijing China 		    ath9k_hw_get_eeprom(ah, EEP_RX_MASK);
3496dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
3497dd1de374Slin wang - Sun Microsystems - Beijing China 		pCap->rx_chainmask =
3498dd1de374Slin wang - Sun Microsystems - Beijing China 		    (ath9k_hw_gpio_get(ah, 0)) ? 0x5 : 0x7;
3499dd1de374Slin wang - Sun Microsystems - Beijing China 	}
3500dd1de374Slin wang - Sun Microsystems - Beijing China 
3501dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!(AR_SREV_9280(ah) && (ah->ah_macRev == 0)))
3502dd1de374Slin wang - Sun Microsystems - Beijing China 		ahp->ah_miscMode |= AR_PCU_MIC_NEW_LOC_ENA;
3503dd1de374Slin wang - Sun Microsystems - Beijing China 
3504dd1de374Slin wang - Sun Microsystems - Beijing China 	pCap->low_2ghz_chan = 2312;
3505dd1de374Slin wang - Sun Microsystems - Beijing China 	pCap->high_2ghz_chan = 2732;
3506dd1de374Slin wang - Sun Microsystems - Beijing China 
3507dd1de374Slin wang - Sun Microsystems - Beijing China 	pCap->low_5ghz_chan = 4920;
3508dd1de374Slin wang - Sun Microsystems - Beijing China 	pCap->high_5ghz_chan = 6100;
3509dd1de374Slin wang - Sun Microsystems - Beijing China 
3510dd1de374Slin wang - Sun Microsystems - Beijing China 	pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP;
3511dd1de374Slin wang - Sun Microsystems - Beijing China 	pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP;
3512dd1de374Slin wang - Sun Microsystems - Beijing China 	pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM;
3513dd1de374Slin wang - Sun Microsystems - Beijing China 
3514dd1de374Slin wang - Sun Microsystems - Beijing China 	pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP;
3515dd1de374Slin wang - Sun Microsystems - Beijing China 	pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
3516dd1de374Slin wang - Sun Microsystems - Beijing China 	pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
3517dd1de374Slin wang - Sun Microsystems - Beijing China 
3518dd1de374Slin wang - Sun Microsystems - Beijing China 	pCap->hw_caps |= ATH9K_HW_CAP_CHAN_SPREAD;
3519*c0c93480Slin wang - Sun Microsystems - Beijing China 
3520dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ah->ah_config.ht_enable)
3521dd1de374Slin wang - Sun Microsystems - Beijing China 		pCap->hw_caps |= ATH9K_HW_CAP_HT;
3522dd1de374Slin wang - Sun Microsystems - Beijing China 	else
3523dd1de374Slin wang - Sun Microsystems - Beijing China 		pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
3524dd1de374Slin wang - Sun Microsystems - Beijing China 
3525dd1de374Slin wang - Sun Microsystems - Beijing China 	pCap->hw_caps |= ATH9K_HW_CAP_GTT;
3526dd1de374Slin wang - Sun Microsystems - Beijing China 	pCap->hw_caps |= ATH9K_HW_CAP_VEOL;
3527dd1de374Slin wang - Sun Microsystems - Beijing China 	pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK;
3528dd1de374Slin wang - Sun Microsystems - Beijing China 	pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH;
3529dd1de374Slin wang - Sun Microsystems - Beijing China 
3530dd1de374Slin wang - Sun Microsystems - Beijing China 	if (capField & AR_EEPROM_EEPCAP_MAXQCU)
3531dd1de374Slin wang - Sun Microsystems - Beijing China 		pCap->total_queues =
3532dd1de374Slin wang - Sun Microsystems - Beijing China 		    MS(capField, AR_EEPROM_EEPCAP_MAXQCU);
3533dd1de374Slin wang - Sun Microsystems - Beijing China 	else
3534dd1de374Slin wang - Sun Microsystems - Beijing China 		pCap->total_queues = ATH9K_NUM_TX_QUEUES;
3535dd1de374Slin wang - Sun Microsystems - Beijing China 
3536dd1de374Slin wang - Sun Microsystems - Beijing China 	if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES)
3537dd1de374Slin wang - Sun Microsystems - Beijing China 		pCap->keycache_size =
3538dd1de374Slin wang - Sun Microsystems - Beijing China 		    1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES);
3539dd1de374Slin wang - Sun Microsystems - Beijing China 	else
3540dd1de374Slin wang - Sun Microsystems - Beijing China 		pCap->keycache_size = AR_KEYTABLE_SIZE;
3541dd1de374Slin wang - Sun Microsystems - Beijing China 
3542dd1de374Slin wang - Sun Microsystems - Beijing China 	pCap->hw_caps |= ATH9K_HW_CAP_FASTCC;
3543dd1de374Slin wang - Sun Microsystems - Beijing China 	pCap->num_mr_retries = 4;
3544dd1de374Slin wang - Sun Microsystems - Beijing China 	pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
3545dd1de374Slin wang - Sun Microsystems - Beijing China 
3546dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9280_10_OR_LATER(ah))
3547dd1de374Slin wang - Sun Microsystems - Beijing China 		pCap->num_gpio_pins = AR928X_NUM_GPIO;
3548dd1de374Slin wang - Sun Microsystems - Beijing China 	else
3549dd1de374Slin wang - Sun Microsystems - Beijing China 		pCap->num_gpio_pins = AR_NUM_GPIO;
3550dd1de374Slin wang - Sun Microsystems - Beijing China 
3551dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9280_10_OR_LATER(ah)) {
3552dd1de374Slin wang - Sun Microsystems - Beijing China 		pCap->hw_caps |= ATH9K_HW_CAP_WOW;
3553dd1de374Slin wang - Sun Microsystems - Beijing China 		pCap->hw_caps |= ATH9K_HW_CAP_WOW_MATCHPATTERN_EXACT;
3554dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
3555dd1de374Slin wang - Sun Microsystems - Beijing China 		pCap->hw_caps &= ~ATH9K_HW_CAP_WOW;
3556dd1de374Slin wang - Sun Microsystems - Beijing China 		pCap->hw_caps &= ~ATH9K_HW_CAP_WOW_MATCHPATTERN_EXACT;
3557dd1de374Slin wang - Sun Microsystems - Beijing China 	}
3558dd1de374Slin wang - Sun Microsystems - Beijing China 
3559dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
3560dd1de374Slin wang - Sun Microsystems - Beijing China 		pCap->hw_caps |= ATH9K_HW_CAP_CST;
3561dd1de374Slin wang - Sun Microsystems - Beijing China 		pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
3562dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
3563dd1de374Slin wang - Sun Microsystems - Beijing China 		pCap->rts_aggr_limit = (8 * 1024);
3564dd1de374Slin wang - Sun Microsystems - Beijing China 	}
3565dd1de374Slin wang - Sun Microsystems - Beijing China 
3566dd1de374Slin wang - Sun Microsystems - Beijing China 	pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM;
3567dd1de374Slin wang - Sun Microsystems - Beijing China 
3568dd1de374Slin wang - Sun Microsystems - Beijing China #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
3569dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_rfsilent = ath9k_hw_get_eeprom(ah, EEP_RF_SILENT);
3570dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ah->ah_rfsilent & EEP_RFSILENT_ENABLED) {
3571dd1de374Slin wang - Sun Microsystems - Beijing China 		ah->ah_rfkill_gpio =
3572dd1de374Slin wang - Sun Microsystems - Beijing China 		    MS(ah->ah_rfsilent, EEP_RFSILENT_GPIO_SEL);
3573dd1de374Slin wang - Sun Microsystems - Beijing China 		ah->ah_rfkill_polarity =
3574dd1de374Slin wang - Sun Microsystems - Beijing China 		    MS(ah->ah_rfsilent, EEP_RFSILENT_POLARITY);
3575dd1de374Slin wang - Sun Microsystems - Beijing China 
3576dd1de374Slin wang - Sun Microsystems - Beijing China 		pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
3577dd1de374Slin wang - Sun Microsystems - Beijing China 	}
3578dd1de374Slin wang - Sun Microsystems - Beijing China #endif
3579dd1de374Slin wang - Sun Microsystems - Beijing China 
3580dd1de374Slin wang - Sun Microsystems - Beijing China 	if ((ah->ah_macVersion == AR_SREV_VERSION_5416_PCI) ||
3581dd1de374Slin wang - Sun Microsystems - Beijing China 	    (ah->ah_macVersion == AR_SREV_VERSION_5416_PCIE) ||
3582dd1de374Slin wang - Sun Microsystems - Beijing China 	    (ah->ah_macVersion == AR_SREV_VERSION_9160) ||
3583dd1de374Slin wang - Sun Microsystems - Beijing China 	    (ah->ah_macVersion == AR_SREV_VERSION_9100) ||
3584dd1de374Slin wang - Sun Microsystems - Beijing China 	    (ah->ah_macVersion == AR_SREV_VERSION_9280))
3585dd1de374Slin wang - Sun Microsystems - Beijing China 		pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
3586dd1de374Slin wang - Sun Microsystems - Beijing China 	else
3587dd1de374Slin wang - Sun Microsystems - Beijing China 		pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP;
3588dd1de374Slin wang - Sun Microsystems - Beijing China 
3589dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
3590dd1de374Slin wang - Sun Microsystems - Beijing China 		pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
3591dd1de374Slin wang - Sun Microsystems - Beijing China 	else
3592dd1de374Slin wang - Sun Microsystems - Beijing China 		pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
3593dd1de374Slin wang - Sun Microsystems - Beijing China 
3594dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ah->ah_currentRDExt & (1 << REG_EXT_JAPAN_MIDBAND)) {
3595dd1de374Slin wang - Sun Microsystems - Beijing China 		pCap->reg_cap =
3596dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3597dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
3598dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_EEPROM_EEREGCAP_EN_KK_U2 |
3599dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
3600dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
3601dd1de374Slin wang - Sun Microsystems - Beijing China 		pCap->reg_cap =
3602dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3603dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
3604dd1de374Slin wang - Sun Microsystems - Beijing China 	}
3605dd1de374Slin wang - Sun Microsystems - Beijing China 
3606dd1de374Slin wang - Sun Microsystems - Beijing China 	pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
3607dd1de374Slin wang - Sun Microsystems - Beijing China 
3608dd1de374Slin wang - Sun Microsystems - Beijing China 	/* ATH9K_HAL_FREQ_BAND_5GHZ == 0 */
3609dd1de374Slin wang - Sun Microsystems - Beijing China 	pCap->num_antcfg_5ghz =
3610dd1de374Slin wang - Sun Microsystems - Beijing China 	    ath9k_hw_get_num_ant_config(ah, 0);
3611dd1de374Slin wang - Sun Microsystems - Beijing China 	/* ATH9K_HAL_FREQ_BAND_2GHZ == 1 */
3612dd1de374Slin wang - Sun Microsystems - Beijing China 	pCap->num_antcfg_2ghz =
3613dd1de374Slin wang - Sun Microsystems - Beijing China 	    ath9k_hw_get_num_ant_config(ah, 1);
3614dd1de374Slin wang - Sun Microsystems - Beijing China 
3615dd1de374Slin wang - Sun Microsystems - Beijing China 	return (B_TRUE);
3616dd1de374Slin wang - Sun Microsystems - Beijing China }
3617dd1de374Slin wang - Sun Microsystems - Beijing China 
3618dd1de374Slin wang - Sun Microsystems - Beijing China boolean_t
3619dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_getcapability(struct ath_hal *ah,
3620dd1de374Slin wang - Sun Microsystems - Beijing China     enum ath9k_capability_type type,
3621dd1de374Slin wang - Sun Microsystems - Beijing China     uint32_t capability, uint32_t *result)
3622dd1de374Slin wang - Sun Microsystems - Beijing China {
3623dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
3624dd1de374Slin wang - Sun Microsystems - Beijing China 	const struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
3625dd1de374Slin wang - Sun Microsystems - Beijing China 
3626dd1de374Slin wang - Sun Microsystems - Beijing China 	switch (type) {
3627dd1de374Slin wang - Sun Microsystems - Beijing China 	case ATH9K_CAP_CIPHER:
3628dd1de374Slin wang - Sun Microsystems - Beijing China 		switch (capability) {
3629dd1de374Slin wang - Sun Microsystems - Beijing China 		case ATH9K_CIPHER_AES_CCM:
3630dd1de374Slin wang - Sun Microsystems - Beijing China 		case ATH9K_CIPHER_AES_OCB:
3631dd1de374Slin wang - Sun Microsystems - Beijing China 		case ATH9K_CIPHER_TKIP:
3632dd1de374Slin wang - Sun Microsystems - Beijing China 		case ATH9K_CIPHER_WEP:
3633dd1de374Slin wang - Sun Microsystems - Beijing China 		case ATH9K_CIPHER_MIC:
3634dd1de374Slin wang - Sun Microsystems - Beijing China 		case ATH9K_CIPHER_CLR:
3635dd1de374Slin wang - Sun Microsystems - Beijing China 			return (B_TRUE);
3636dd1de374Slin wang - Sun Microsystems - Beijing China 		default:
3637dd1de374Slin wang - Sun Microsystems - Beijing China 			return (B_FALSE);
3638dd1de374Slin wang - Sun Microsystems - Beijing China 		}
3639dd1de374Slin wang - Sun Microsystems - Beijing China 	case ATH9K_CAP_TKIP_MIC:
3640dd1de374Slin wang - Sun Microsystems - Beijing China 		switch (capability) {
3641dd1de374Slin wang - Sun Microsystems - Beijing China 		case 0:
3642dd1de374Slin wang - Sun Microsystems - Beijing China 			return (B_TRUE);
3643dd1de374Slin wang - Sun Microsystems - Beijing China 		case 1:
3644dd1de374Slin wang - Sun Microsystems - Beijing China 			return ((ahp->ah_staId1Defaults &
3645dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR_STA_ID1_CRPT_MIC_ENABLE) ? B_TRUE :
3646dd1de374Slin wang - Sun Microsystems - Beijing China 			    B_FALSE);
3647dd1de374Slin wang - Sun Microsystems - Beijing China 		}
3648dd1de374Slin wang - Sun Microsystems - Beijing China 		/*FALLTHRU*/
3649dd1de374Slin wang - Sun Microsystems - Beijing China 	case ATH9K_CAP_TKIP_SPLIT:
3650dd1de374Slin wang - Sun Microsystems - Beijing China 		return ((ahp->ah_miscMode & AR_PCU_MIC_NEW_LOC_ENA) ?
3651dd1de374Slin wang - Sun Microsystems - Beijing China 		    B_FALSE : B_TRUE);
3652dd1de374Slin wang - Sun Microsystems - Beijing China 	case ATH9K_CAP_WME_TKIPMIC:
3653dd1de374Slin wang - Sun Microsystems - Beijing China 		return (0);
3654dd1de374Slin wang - Sun Microsystems - Beijing China 	case ATH9K_CAP_PHYCOUNTERS:
3655dd1de374Slin wang - Sun Microsystems - Beijing China 		return (ahp->ah_hasHwPhyCounters ? 0 : -ENXIO);
3656dd1de374Slin wang - Sun Microsystems - Beijing China 	case ATH9K_CAP_DIVERSITY:
3657dd1de374Slin wang - Sun Microsystems - Beijing China 		return ((REG_READ(ah, AR_PHY_CCK_DETECT) &
3658dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV) ?
3659dd1de374Slin wang - Sun Microsystems - Beijing China 		    B_TRUE : B_FALSE);
3660dd1de374Slin wang - Sun Microsystems - Beijing China 	case ATH9K_CAP_PHYDIAG:
3661dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_TRUE);
3662dd1de374Slin wang - Sun Microsystems - Beijing China 	case ATH9K_CAP_MCAST_KEYSRCH:
3663dd1de374Slin wang - Sun Microsystems - Beijing China 		switch (capability) {
3664dd1de374Slin wang - Sun Microsystems - Beijing China 		case 0:
3665dd1de374Slin wang - Sun Microsystems - Beijing China 			return (B_TRUE);
3666dd1de374Slin wang - Sun Microsystems - Beijing China 		case 1:
3667dd1de374Slin wang - Sun Microsystems - Beijing China 			if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) {
3668dd1de374Slin wang - Sun Microsystems - Beijing China 				return (B_FALSE);
3669dd1de374Slin wang - Sun Microsystems - Beijing China 			} else {
3670dd1de374Slin wang - Sun Microsystems - Beijing China 				return ((ahp->ah_staId1Defaults &
3671dd1de374Slin wang - Sun Microsystems - Beijing China 				    AR_STA_ID1_MCAST_KSRCH) ? B_TRUE :
3672dd1de374Slin wang - Sun Microsystems - Beijing China 				    B_FALSE);
3673dd1de374Slin wang - Sun Microsystems - Beijing China 			}
3674dd1de374Slin wang - Sun Microsystems - Beijing China 		}
3675dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_FALSE);
3676dd1de374Slin wang - Sun Microsystems - Beijing China 	case ATH9K_CAP_TSF_ADJUST:
3677dd1de374Slin wang - Sun Microsystems - Beijing China 		return ((ahp->ah_miscMode & AR_PCU_TX_ADD_TSF) ?
3678dd1de374Slin wang - Sun Microsystems - Beijing China 		    B_TRUE : B_FALSE);
3679dd1de374Slin wang - Sun Microsystems - Beijing China 	case ATH9K_CAP_RFSILENT:
3680dd1de374Slin wang - Sun Microsystems - Beijing China 		if (capability == 3)
3681dd1de374Slin wang - Sun Microsystems - Beijing China 			return (B_FALSE);
3682dd1de374Slin wang - Sun Microsystems - Beijing China 		/*FALLTHRU*/
3683dd1de374Slin wang - Sun Microsystems - Beijing China 	case ATH9K_CAP_ANT_CFG_2GHZ:
3684dd1de374Slin wang - Sun Microsystems - Beijing China 		*result = pCap->num_antcfg_2ghz;
3685dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_TRUE);
3686dd1de374Slin wang - Sun Microsystems - Beijing China 	case ATH9K_CAP_ANT_CFG_5GHZ:
3687dd1de374Slin wang - Sun Microsystems - Beijing China 		*result = pCap->num_antcfg_5ghz;
3688dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_TRUE);
3689dd1de374Slin wang - Sun Microsystems - Beijing China 	case ATH9K_CAP_TXPOW:
3690dd1de374Slin wang - Sun Microsystems - Beijing China 		switch (capability) {
3691dd1de374Slin wang - Sun Microsystems - Beijing China 		case 0:
3692dd1de374Slin wang - Sun Microsystems - Beijing China 			return (0);
3693dd1de374Slin wang - Sun Microsystems - Beijing China 		case 1:
3694dd1de374Slin wang - Sun Microsystems - Beijing China 			*result = ah->ah_powerLimit;
3695dd1de374Slin wang - Sun Microsystems - Beijing China 			return (0);
3696dd1de374Slin wang - Sun Microsystems - Beijing China 		case 2:
3697dd1de374Slin wang - Sun Microsystems - Beijing China 			*result = ah->ah_maxPowerLevel;
3698dd1de374Slin wang - Sun Microsystems - Beijing China 			return (0);
3699dd1de374Slin wang - Sun Microsystems - Beijing China 		case 3:
3700dd1de374Slin wang - Sun Microsystems - Beijing China 			*result = ah->ah_tpScale;
3701dd1de374Slin wang - Sun Microsystems - Beijing China 			return (0);
3702dd1de374Slin wang - Sun Microsystems - Beijing China 		}
3703dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_FALSE);
3704dd1de374Slin wang - Sun Microsystems - Beijing China 	default:
3705dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_FALSE);
3706dd1de374Slin wang - Sun Microsystems - Beijing China 	}
3707dd1de374Slin wang - Sun Microsystems - Beijing China }
3708dd1de374Slin wang - Sun Microsystems - Beijing China 
3709dd1de374Slin wang - Sun Microsystems - Beijing China /* ARGSUSED */
3710dd1de374Slin wang - Sun Microsystems - Beijing China boolean_t
3711dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_setcapability(struct ath_hal *ah,
3712dd1de374Slin wang - Sun Microsystems - Beijing China     enum ath9k_capability_type type,
3713dd1de374Slin wang - Sun Microsystems - Beijing China     uint32_t capability, uint32_t setting,
3714dd1de374Slin wang - Sun Microsystems - Beijing China     int *status)
3715dd1de374Slin wang - Sun Microsystems - Beijing China {
3716dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
3717dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t v;
3718dd1de374Slin wang - Sun Microsystems - Beijing China 
3719dd1de374Slin wang - Sun Microsystems - Beijing China 	switch (type) {
3720dd1de374Slin wang - Sun Microsystems - Beijing China 	case ATH9K_CAP_TKIP_MIC:
3721dd1de374Slin wang - Sun Microsystems - Beijing China 		if (setting)
3722dd1de374Slin wang - Sun Microsystems - Beijing China 			ahp->ah_staId1Defaults |=
3723dd1de374Slin wang - Sun Microsystems - Beijing China 			    AR_STA_ID1_CRPT_MIC_ENABLE;
3724dd1de374Slin wang - Sun Microsystems - Beijing China 		else
3725dd1de374Slin wang - Sun Microsystems - Beijing China 			ahp->ah_staId1Defaults &=
3726dd1de374Slin wang - Sun Microsystems - Beijing China 			    ~AR_STA_ID1_CRPT_MIC_ENABLE;
3727dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_TRUE);
3728dd1de374Slin wang - Sun Microsystems - Beijing China 	case ATH9K_CAP_DIVERSITY:
3729dd1de374Slin wang - Sun Microsystems - Beijing China 		v = REG_READ(ah, AR_PHY_CCK_DETECT);
3730dd1de374Slin wang - Sun Microsystems - Beijing China 		if (setting)
3731dd1de374Slin wang - Sun Microsystems - Beijing China 			v |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3732dd1de374Slin wang - Sun Microsystems - Beijing China 		else
3733dd1de374Slin wang - Sun Microsystems - Beijing China 			v &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3734dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_PHY_CCK_DETECT, v);
3735dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_TRUE);
3736dd1de374Slin wang - Sun Microsystems - Beijing China 	case ATH9K_CAP_MCAST_KEYSRCH:
3737dd1de374Slin wang - Sun Microsystems - Beijing China 		if (setting)
3738dd1de374Slin wang - Sun Microsystems - Beijing China 			ahp->ah_staId1Defaults |= AR_STA_ID1_MCAST_KSRCH;
3739dd1de374Slin wang - Sun Microsystems - Beijing China 		else
3740dd1de374Slin wang - Sun Microsystems - Beijing China 			ahp->ah_staId1Defaults &= ~AR_STA_ID1_MCAST_KSRCH;
3741dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_TRUE);
3742dd1de374Slin wang - Sun Microsystems - Beijing China 	case ATH9K_CAP_TSF_ADJUST:
3743dd1de374Slin wang - Sun Microsystems - Beijing China 		if (setting)
3744dd1de374Slin wang - Sun Microsystems - Beijing China 			ahp->ah_miscMode |= AR_PCU_TX_ADD_TSF;
3745dd1de374Slin wang - Sun Microsystems - Beijing China 		else
3746dd1de374Slin wang - Sun Microsystems - Beijing China 			ahp->ah_miscMode &= ~AR_PCU_TX_ADD_TSF;
3747dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_TRUE);
3748dd1de374Slin wang - Sun Microsystems - Beijing China 	default:
3749dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_FALSE);
3750dd1de374Slin wang - Sun Microsystems - Beijing China 	}
3751dd1de374Slin wang - Sun Microsystems - Beijing China }
3752dd1de374Slin wang - Sun Microsystems - Beijing China 
3753dd1de374Slin wang - Sun Microsystems - Beijing China /* GPIO / RFKILL / Antennae */
3754dd1de374Slin wang - Sun Microsystems - Beijing China 
3755dd1de374Slin wang - Sun Microsystems - Beijing China static void
3756dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_gpio_cfg_output_mux(struct ath_hal *ah,
3757dd1de374Slin wang - Sun Microsystems - Beijing China     uint32_t gpio, uint32_t type)
3758dd1de374Slin wang - Sun Microsystems - Beijing China {
3759dd1de374Slin wang - Sun Microsystems - Beijing China 	int addr;
3760dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t gpio_shift, tmp;
3761dd1de374Slin wang - Sun Microsystems - Beijing China 
3762dd1de374Slin wang - Sun Microsystems - Beijing China 	if (gpio > 11)
3763dd1de374Slin wang - Sun Microsystems - Beijing China 		addr = AR_GPIO_OUTPUT_MUX3;
3764dd1de374Slin wang - Sun Microsystems - Beijing China 	else if (gpio > 5)
3765dd1de374Slin wang - Sun Microsystems - Beijing China 		addr = AR_GPIO_OUTPUT_MUX2;
3766dd1de374Slin wang - Sun Microsystems - Beijing China 	else
3767dd1de374Slin wang - Sun Microsystems - Beijing China 		addr = AR_GPIO_OUTPUT_MUX1;
3768dd1de374Slin wang - Sun Microsystems - Beijing China 
3769dd1de374Slin wang - Sun Microsystems - Beijing China 	gpio_shift = (gpio % 6) * 5;
3770dd1de374Slin wang - Sun Microsystems - Beijing China 
3771dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9280_20_OR_LATER(ah) ||
3772dd1de374Slin wang - Sun Microsystems - Beijing China 	    (addr != AR_GPIO_OUTPUT_MUX1)) {
3773dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_RMW(ah, addr, (type << gpio_shift),
3774dd1de374Slin wang - Sun Microsystems - Beijing China 		    (0x1f << gpio_shift));
3775dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
3776dd1de374Slin wang - Sun Microsystems - Beijing China 		tmp = REG_READ(ah, addr);
3777dd1de374Slin wang - Sun Microsystems - Beijing China 		tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
3778dd1de374Slin wang - Sun Microsystems - Beijing China 		tmp &= ~(0x1f << gpio_shift);
3779dd1de374Slin wang - Sun Microsystems - Beijing China 		tmp |= (type << gpio_shift);
3780dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, addr, tmp);
3781dd1de374Slin wang - Sun Microsystems - Beijing China 	}
3782dd1de374Slin wang - Sun Microsystems - Beijing China }
3783dd1de374Slin wang - Sun Microsystems - Beijing China 
3784dd1de374Slin wang - Sun Microsystems - Beijing China void
3785dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_cfg_gpio_input(struct ath_hal *ah, uint32_t gpio)
3786dd1de374Slin wang - Sun Microsystems - Beijing China {
3787dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t gpio_shift;
3788dd1de374Slin wang - Sun Microsystems - Beijing China 
3789dd1de374Slin wang - Sun Microsystems - Beijing China 	ASSERT(gpio < ah->ah_caps.num_gpio_pins);
3790dd1de374Slin wang - Sun Microsystems - Beijing China 
3791dd1de374Slin wang - Sun Microsystems - Beijing China 	gpio_shift = gpio << 1;
3792dd1de374Slin wang - Sun Microsystems - Beijing China 
3793dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_RMW(ah,
3794dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_GPIO_OE_OUT,
3795dd1de374Slin wang - Sun Microsystems - Beijing China 	    (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
3796dd1de374Slin wang - Sun Microsystems - Beijing China 	    (AR_GPIO_OE_OUT_DRV << gpio_shift));
3797dd1de374Slin wang - Sun Microsystems - Beijing China }
3798dd1de374Slin wang - Sun Microsystems - Beijing China 
3799dd1de374Slin wang - Sun Microsystems - Beijing China uint32_t
3800dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_gpio_get(struct ath_hal *ah, uint32_t gpio)
3801dd1de374Slin wang - Sun Microsystems - Beijing China {
3802dd1de374Slin wang - Sun Microsystems - Beijing China 	if (gpio >= ah->ah_caps.num_gpio_pins)
3803dd1de374Slin wang - Sun Microsystems - Beijing China 		return (0xffffffff);
3804dd1de374Slin wang - Sun Microsystems - Beijing China 
3805dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9280_10_OR_LATER(ah)) {
3806dd1de374Slin wang - Sun Microsystems - Beijing China 		return ((MS(REG_READ(ah, AR_GPIO_IN_OUT),
3807dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR928X_GPIO_IN_VAL) & AR_GPIO_BIT(gpio)) != 0);
3808dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
3809dd1de374Slin wang - Sun Microsystems - Beijing China 		return ((MS(REG_READ(ah,
3810dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_GPIO_IN_OUT), AR_GPIO_IN_VAL) &
3811dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_GPIO_BIT(gpio)) != 0);
3812dd1de374Slin wang - Sun Microsystems - Beijing China 	}
3813dd1de374Slin wang - Sun Microsystems - Beijing China }
3814dd1de374Slin wang - Sun Microsystems - Beijing China 
3815dd1de374Slin wang - Sun Microsystems - Beijing China void
3816dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_cfg_output(struct ath_hal *ah, uint32_t gpio,
3817dd1de374Slin wang - Sun Microsystems - Beijing China     uint32_t ah_signal_type)
3818dd1de374Slin wang - Sun Microsystems - Beijing China {
3819dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t gpio_shift;
3820dd1de374Slin wang - Sun Microsystems - Beijing China 
3821dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
3822dd1de374Slin wang - Sun Microsystems - Beijing China 
3823dd1de374Slin wang - Sun Microsystems - Beijing China 	gpio_shift = 2 * gpio;
3824dd1de374Slin wang - Sun Microsystems - Beijing China 
3825dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_RMW(ah,
3826dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_GPIO_OE_OUT,
3827dd1de374Slin wang - Sun Microsystems - Beijing China 	    (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
3828dd1de374Slin wang - Sun Microsystems - Beijing China 	    (AR_GPIO_OE_OUT_DRV << gpio_shift));
3829dd1de374Slin wang - Sun Microsystems - Beijing China }
3830dd1de374Slin wang - Sun Microsystems - Beijing China 
3831dd1de374Slin wang - Sun Microsystems - Beijing China void
3832dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_set_gpio(struct ath_hal *ah, uint32_t gpio, uint32_t val)
3833dd1de374Slin wang - Sun Microsystems - Beijing China {
3834dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
3835dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_GPIO_BIT(gpio));
3836dd1de374Slin wang - Sun Microsystems - Beijing China }
3837dd1de374Slin wang - Sun Microsystems - Beijing China 
3838dd1de374Slin wang - Sun Microsystems - Beijing China #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
3839dd1de374Slin wang - Sun Microsystems - Beijing China void
3840dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_enable_rfkill(struct ath_hal *ah)
3841dd1de374Slin wang - Sun Microsystems - Beijing China {
3842dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
3843dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_GPIO_INPUT_EN_VAL_RFSILENT_BB);
3844dd1de374Slin wang - Sun Microsystems - Beijing China 
3845dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_CLR_BIT(ah, AR_GPIO_INPUT_MUX2,
3846dd1de374Slin wang - Sun Microsystems - Beijing China 	    AR_GPIO_INPUT_MUX2_RFSILENT);
3847dd1de374Slin wang - Sun Microsystems - Beijing China 
3848dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_cfg_gpio_input(ah, ah->ah_rfkill_gpio);
3849dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_SET_BIT(ah, AR_PHY_TEST, RFSILENT_BB);
3850dd1de374Slin wang - Sun Microsystems - Beijing China }
3851dd1de374Slin wang - Sun Microsystems - Beijing China #endif
3852dd1de374Slin wang - Sun Microsystems - Beijing China 
3853dd1de374Slin wang - Sun Microsystems - Beijing China int
3854dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_select_antconfig(struct ath_hal *ah, uint32_t cfg)
3855dd1de374Slin wang - Sun Microsystems - Beijing China {
3856dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath9k_channel *chan = ah->ah_curchan;
3857dd1de374Slin wang - Sun Microsystems - Beijing China 	const struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
3858dd1de374Slin wang - Sun Microsystems - Beijing China 	uint16_t ant_config;
3859dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t halNumAntConfig;
3860dd1de374Slin wang - Sun Microsystems - Beijing China 
3861dd1de374Slin wang - Sun Microsystems - Beijing China 	halNumAntConfig = IS_CHAN_2GHZ(chan) ?
3862dd1de374Slin wang - Sun Microsystems - Beijing China 	    pCap->num_antcfg_2ghz : pCap->num_antcfg_5ghz;
3863dd1de374Slin wang - Sun Microsystems - Beijing China 
3864dd1de374Slin wang - Sun Microsystems - Beijing China 	if (cfg < halNumAntConfig) {
3865dd1de374Slin wang - Sun Microsystems - Beijing China 		if (!ath9k_hw_get_eeprom_antenna_cfg(ah, chan,
3866dd1de374Slin wang - Sun Microsystems - Beijing China 		    cfg, &ant_config)) {
3867dd1de374Slin wang - Sun Microsystems - Beijing China 			REG_WRITE(ah, AR_PHY_SWITCH_COM, ant_config);
3868dd1de374Slin wang - Sun Microsystems - Beijing China 			return (0);
3869dd1de374Slin wang - Sun Microsystems - Beijing China 		}
3870dd1de374Slin wang - Sun Microsystems - Beijing China 	}
3871dd1de374Slin wang - Sun Microsystems - Beijing China 
3872dd1de374Slin wang - Sun Microsystems - Beijing China 	return (-EINVAL);
3873dd1de374Slin wang - Sun Microsystems - Beijing China }
3874dd1de374Slin wang - Sun Microsystems - Beijing China 
3875dd1de374Slin wang - Sun Microsystems - Beijing China uint32_t
3876dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_getdefantenna(struct ath_hal *ah)
3877dd1de374Slin wang - Sun Microsystems - Beijing China {
3878dd1de374Slin wang - Sun Microsystems - Beijing China 	return (REG_READ(ah, AR_DEF_ANTENNA) & 0x7);
3879dd1de374Slin wang - Sun Microsystems - Beijing China }
3880dd1de374Slin wang - Sun Microsystems - Beijing China 
3881dd1de374Slin wang - Sun Microsystems - Beijing China void
3882dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_setantenna(struct ath_hal *ah, uint32_t antenna)
3883dd1de374Slin wang - Sun Microsystems - Beijing China {
3884dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
3885dd1de374Slin wang - Sun Microsystems - Beijing China }
3886dd1de374Slin wang - Sun Microsystems - Beijing China 
3887dd1de374Slin wang - Sun Microsystems - Beijing China /* ARGSUSED */
3888dd1de374Slin wang - Sun Microsystems - Beijing China boolean_t
3889dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_setantennaswitch(struct ath_hal *ah,
3890dd1de374Slin wang - Sun Microsystems - Beijing China     enum ath9k_ant_setting settings,
3891dd1de374Slin wang - Sun Microsystems - Beijing China     struct ath9k_channel *chan,
3892dd1de374Slin wang - Sun Microsystems - Beijing China     uint8_t *tx_chainmask,
3893dd1de374Slin wang - Sun Microsystems - Beijing China     uint8_t *rx_chainmask,
3894dd1de374Slin wang - Sun Microsystems - Beijing China     uint8_t *antenna_cfgd)
3895dd1de374Slin wang - Sun Microsystems - Beijing China {
3896dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
3897dd1de374Slin wang - Sun Microsystems - Beijing China 	static uint8_t tx_chainmask_cfg, rx_chainmask_cfg;
3898dd1de374Slin wang - Sun Microsystems - Beijing China 
3899dd1de374Slin wang - Sun Microsystems - Beijing China 	if (AR_SREV_9280(ah)) {
3900dd1de374Slin wang - Sun Microsystems - Beijing China 		if (!tx_chainmask_cfg) {
3901dd1de374Slin wang - Sun Microsystems - Beijing China 
3902dd1de374Slin wang - Sun Microsystems - Beijing China 			tx_chainmask_cfg = *tx_chainmask;
3903dd1de374Slin wang - Sun Microsystems - Beijing China 			rx_chainmask_cfg = *rx_chainmask;
3904dd1de374Slin wang - Sun Microsystems - Beijing China 		}
3905dd1de374Slin wang - Sun Microsystems - Beijing China 
3906dd1de374Slin wang - Sun Microsystems - Beijing China 		switch (settings) {
3907dd1de374Slin wang - Sun Microsystems - Beijing China 		case ATH9K_ANT_FIXED_A:
3908dd1de374Slin wang - Sun Microsystems - Beijing China 			*tx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
3909dd1de374Slin wang - Sun Microsystems - Beijing China 			*rx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
3910dd1de374Slin wang - Sun Microsystems - Beijing China 			*antenna_cfgd = B_TRUE;
3911dd1de374Slin wang - Sun Microsystems - Beijing China 			break;
3912dd1de374Slin wang - Sun Microsystems - Beijing China 		case ATH9K_ANT_FIXED_B:
3913dd1de374Slin wang - Sun Microsystems - Beijing China 			if (ah->ah_caps.tx_chainmask >
3914dd1de374Slin wang - Sun Microsystems - Beijing China 			    ATH9K_ANTENNA1_CHAINMASK) {
3915dd1de374Slin wang - Sun Microsystems - Beijing China 				*tx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
3916dd1de374Slin wang - Sun Microsystems - Beijing China 			}
3917dd1de374Slin wang - Sun Microsystems - Beijing China 			*rx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
3918dd1de374Slin wang - Sun Microsystems - Beijing China 			*antenna_cfgd = B_TRUE;
3919dd1de374Slin wang - Sun Microsystems - Beijing China 			break;
3920dd1de374Slin wang - Sun Microsystems - Beijing China 		case ATH9K_ANT_VARIABLE:
3921dd1de374Slin wang - Sun Microsystems - Beijing China 			*tx_chainmask = tx_chainmask_cfg;
3922dd1de374Slin wang - Sun Microsystems - Beijing China 			*rx_chainmask = rx_chainmask_cfg;
3923dd1de374Slin wang - Sun Microsystems - Beijing China 			*antenna_cfgd = B_TRUE;
3924dd1de374Slin wang - Sun Microsystems - Beijing China 			break;
3925dd1de374Slin wang - Sun Microsystems - Beijing China 		default:
3926dd1de374Slin wang - Sun Microsystems - Beijing China 			break;
3927dd1de374Slin wang - Sun Microsystems - Beijing China 		}
3928dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
3929dd1de374Slin wang - Sun Microsystems - Beijing China 		ahp->ah_diversityControl = settings;
3930dd1de374Slin wang - Sun Microsystems - Beijing China 	}
3931dd1de374Slin wang - Sun Microsystems - Beijing China 
3932dd1de374Slin wang - Sun Microsystems - Beijing China 	return (B_TRUE);
3933dd1de374Slin wang - Sun Microsystems - Beijing China }
3934dd1de374Slin wang - Sun Microsystems - Beijing China 
3935dd1de374Slin wang - Sun Microsystems - Beijing China /* General Operation */
3936dd1de374Slin wang - Sun Microsystems - Beijing China 
3937dd1de374Slin wang - Sun Microsystems - Beijing China uint32_t
3938dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_getrxfilter(struct ath_hal *ah)
3939dd1de374Slin wang - Sun Microsystems - Beijing China {
3940dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t bits = REG_READ(ah, AR_RX_FILTER);
3941dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t phybits = REG_READ(ah, AR_PHY_ERR);
3942dd1de374Slin wang - Sun Microsystems - Beijing China 
3943dd1de374Slin wang - Sun Microsystems - Beijing China 	if (phybits & AR_PHY_ERR_RADAR)
3944dd1de374Slin wang - Sun Microsystems - Beijing China 		bits |= ATH9K_RX_FILTER_PHYRADAR;
3945dd1de374Slin wang - Sun Microsystems - Beijing China 	if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
3946dd1de374Slin wang - Sun Microsystems - Beijing China 		bits |= ATH9K_RX_FILTER_PHYERR;
3947dd1de374Slin wang - Sun Microsystems - Beijing China 
3948dd1de374Slin wang - Sun Microsystems - Beijing China 	return (bits);
3949dd1de374Slin wang - Sun Microsystems - Beijing China }
3950dd1de374Slin wang - Sun Microsystems - Beijing China 
3951dd1de374Slin wang - Sun Microsystems - Beijing China void
3952dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_setrxfilter(struct ath_hal *ah, uint32_t bits)
3953dd1de374Slin wang - Sun Microsystems - Beijing China {
3954dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t phybits;
3955dd1de374Slin wang - Sun Microsystems - Beijing China 
3956dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_RX_FILTER, (bits & 0xffff) | AR_RX_COMPR_BAR);
3957dd1de374Slin wang - Sun Microsystems - Beijing China 	phybits = 0;
3958dd1de374Slin wang - Sun Microsystems - Beijing China 	if (bits & ATH9K_RX_FILTER_PHYRADAR)
3959dd1de374Slin wang - Sun Microsystems - Beijing China 		phybits |= AR_PHY_ERR_RADAR;
3960dd1de374Slin wang - Sun Microsystems - Beijing China 	if (bits & ATH9K_RX_FILTER_PHYERR)
3961dd1de374Slin wang - Sun Microsystems - Beijing China 		phybits |= AR_PHY_ERR_OFDM_TIMING |
3962dd1de374Slin wang - Sun Microsystems - Beijing China 		    AR_PHY_ERR_CCK_TIMING;
3963dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_PHY_ERR, phybits);
3964dd1de374Slin wang - Sun Microsystems - Beijing China 
3965dd1de374Slin wang - Sun Microsystems - Beijing China 	if (phybits)
3966dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_RXCFG,
3967dd1de374Slin wang - Sun Microsystems - Beijing China 		    REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
3968dd1de374Slin wang - Sun Microsystems - Beijing China 	else
3969dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_RXCFG,
3970dd1de374Slin wang - Sun Microsystems - Beijing China 		    REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA);
3971dd1de374Slin wang - Sun Microsystems - Beijing China }
3972dd1de374Slin wang - Sun Microsystems - Beijing China 
3973dd1de374Slin wang - Sun Microsystems - Beijing China boolean_t
3974dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_phy_disable(struct ath_hal *ah)
3975dd1de374Slin wang - Sun Microsystems - Beijing China {
3976dd1de374Slin wang - Sun Microsystems - Beijing China 	return (ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM));
3977dd1de374Slin wang - Sun Microsystems - Beijing China }
3978dd1de374Slin wang - Sun Microsystems - Beijing China 
3979dd1de374Slin wang - Sun Microsystems - Beijing China boolean_t
3980dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_disable(struct ath_hal *ah)
3981dd1de374Slin wang - Sun Microsystems - Beijing China {
3982dd1de374Slin wang - Sun Microsystems - Beijing China 	if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
3983dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_FALSE);
3984dd1de374Slin wang - Sun Microsystems - Beijing China 
3985dd1de374Slin wang - Sun Microsystems - Beijing China 	return (ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD));
3986dd1de374Slin wang - Sun Microsystems - Beijing China }
3987dd1de374Slin wang - Sun Microsystems - Beijing China 
3988dd1de374Slin wang - Sun Microsystems - Beijing China boolean_t
3989dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_set_txpowerlimit(struct ath_hal *ah, uint32_t limit)
3990dd1de374Slin wang - Sun Microsystems - Beijing China {
3991dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath9k_channel *chan = ah->ah_curchan;
3992dd1de374Slin wang - Sun Microsystems - Beijing China 
3993dd1de374Slin wang - Sun Microsystems - Beijing China 	/* LINT */
3994dd1de374Slin wang - Sun Microsystems - Beijing China 	ah->ah_powerLimit = (uint16_t)min(limit, (uint32_t)MAX_RATE_POWER);
3995dd1de374Slin wang - Sun Microsystems - Beijing China 
3996dd1de374Slin wang - Sun Microsystems - Beijing China 	if (ath9k_hw_set_txpower(ah, chan,
3997dd1de374Slin wang - Sun Microsystems - Beijing China 	    ath9k_regd_get_ctl(ah, chan),
3998dd1de374Slin wang - Sun Microsystems - Beijing China 	    ath9k_regd_get_antenna_allowed(ah, chan),
3999dd1de374Slin wang - Sun Microsystems - Beijing China 	    chan->maxRegTxPower * 2,
4000dd1de374Slin wang - Sun Microsystems - Beijing China 	    ARN_MIN((uint32_t)MAX_RATE_POWER,
4001dd1de374Slin wang - Sun Microsystems - Beijing China 	    (uint32_t)ah->ah_powerLimit)) != 0)
4002dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_FALSE);
4003dd1de374Slin wang - Sun Microsystems - Beijing China 
4004dd1de374Slin wang - Sun Microsystems - Beijing China 	return (B_TRUE);
4005dd1de374Slin wang - Sun Microsystems - Beijing China }
4006dd1de374Slin wang - Sun Microsystems - Beijing China 
4007dd1de374Slin wang - Sun Microsystems - Beijing China void
4008dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_getmac(struct ath_hal *ah, uint8_t *mac)
4009dd1de374Slin wang - Sun Microsystems - Beijing China {
4010dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
4011dd1de374Slin wang - Sun Microsystems - Beijing China 
4012dd1de374Slin wang - Sun Microsystems - Beijing China 	(void) memcpy(mac, ahp->ah_macaddr, 6);
4013dd1de374Slin wang - Sun Microsystems - Beijing China }
4014dd1de374Slin wang - Sun Microsystems - Beijing China 
4015dd1de374Slin wang - Sun Microsystems - Beijing China boolean_t
4016dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_setmac(struct ath_hal *ah, const uint8_t *mac)
4017dd1de374Slin wang - Sun Microsystems - Beijing China {
4018dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
4019dd1de374Slin wang - Sun Microsystems - Beijing China 
4020dd1de374Slin wang - Sun Microsystems - Beijing China 	(void) memcpy(ahp->ah_macaddr, mac, 6);
4021dd1de374Slin wang - Sun Microsystems - Beijing China 
4022dd1de374Slin wang - Sun Microsystems - Beijing China 	return (B_TRUE);
4023dd1de374Slin wang - Sun Microsystems - Beijing China }
4024dd1de374Slin wang - Sun Microsystems - Beijing China 
4025dd1de374Slin wang - Sun Microsystems - Beijing China void
4026dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_setopmode(struct ath_hal *ah)
4027dd1de374Slin wang - Sun Microsystems - Beijing China {
4028dd1de374Slin wang - Sun Microsystems - Beijing China 	ath9k_hw_set_operating_mode(ah, ah->ah_opmode);
4029dd1de374Slin wang - Sun Microsystems - Beijing China }
4030dd1de374Slin wang - Sun Microsystems - Beijing China 
4031dd1de374Slin wang - Sun Microsystems - Beijing China void
4032dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_setmcastfilter(struct ath_hal *ah, uint32_t filter0, uint32_t filter1)
4033dd1de374Slin wang - Sun Microsystems - Beijing China {
4034dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_MCAST_FIL0, filter0);
4035dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_MCAST_FIL1, filter1);
4036dd1de374Slin wang - Sun Microsystems - Beijing China }
4037dd1de374Slin wang - Sun Microsystems - Beijing China 
4038dd1de374Slin wang - Sun Microsystems - Beijing China void
4039dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_getbssidmask(struct ath_hal *ah, uint8_t *mask)
4040dd1de374Slin wang - Sun Microsystems - Beijing China {
4041dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
4042dd1de374Slin wang - Sun Microsystems - Beijing China 
4043dd1de374Slin wang - Sun Microsystems - Beijing China 	(void) memcpy(mask, ahp->ah_bssidmask, 6);
4044dd1de374Slin wang - Sun Microsystems - Beijing China }
4045dd1de374Slin wang - Sun Microsystems - Beijing China 
4046dd1de374Slin wang - Sun Microsystems - Beijing China boolean_t
4047dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_setbssidmask(struct ath_hal *ah, const uint8_t *mask)
4048dd1de374Slin wang - Sun Microsystems - Beijing China {
4049dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
4050dd1de374Slin wang - Sun Microsystems - Beijing China 
4051dd1de374Slin wang - Sun Microsystems - Beijing China 	(void) memcpy(ahp->ah_bssidmask, mask, 6);
4052dd1de374Slin wang - Sun Microsystems - Beijing China 
4053dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_BSSMSKL, ARN_LE_READ_32(ahp->ah_bssidmask));
4054dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_BSSMSKU, ARN_LE_READ_16(ahp->ah_bssidmask + 4));
4055dd1de374Slin wang - Sun Microsystems - Beijing China 
4056dd1de374Slin wang - Sun Microsystems - Beijing China 	return (B_TRUE);
4057dd1de374Slin wang - Sun Microsystems - Beijing China }
4058dd1de374Slin wang - Sun Microsystems - Beijing China 
4059dd1de374Slin wang - Sun Microsystems - Beijing China void
4060dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_write_associd(struct ath_hal *ah,
4061dd1de374Slin wang - Sun Microsystems - Beijing China     const uint8_t *bssid, uint16_t assocId)
4062dd1de374Slin wang - Sun Microsystems - Beijing China {
4063dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
4064dd1de374Slin wang - Sun Microsystems - Beijing China 
4065dd1de374Slin wang - Sun Microsystems - Beijing China 	(void) memcpy(ahp->ah_bssid, bssid, 6);
4066dd1de374Slin wang - Sun Microsystems - Beijing China 	ahp->ah_assocId = assocId;
4067dd1de374Slin wang - Sun Microsystems - Beijing China 
4068dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_BSS_ID0, ARN_LE_READ_32(ahp->ah_bssid));
4069dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_BSS_ID1, ARN_LE_READ_16(ahp->ah_bssid + 4) |
4070dd1de374Slin wang - Sun Microsystems - Beijing China 	    ((assocId & 0x3fff) << AR_BSS_ID1_AID_S));
4071dd1de374Slin wang - Sun Microsystems - Beijing China }
4072dd1de374Slin wang - Sun Microsystems - Beijing China 
4073dd1de374Slin wang - Sun Microsystems - Beijing China uint64_t
4074dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_gettsf64(struct ath_hal *ah)
4075dd1de374Slin wang - Sun Microsystems - Beijing China {
4076dd1de374Slin wang - Sun Microsystems - Beijing China 	uint64_t tsf;
4077dd1de374Slin wang - Sun Microsystems - Beijing China 
4078dd1de374Slin wang - Sun Microsystems - Beijing China 	tsf = REG_READ(ah, AR_TSF_U32);
4079dd1de374Slin wang - Sun Microsystems - Beijing China 	tsf = (tsf << 32) | REG_READ(ah, AR_TSF_L32);
4080dd1de374Slin wang - Sun Microsystems - Beijing China 
4081dd1de374Slin wang - Sun Microsystems - Beijing China 	return (tsf);
4082dd1de374Slin wang - Sun Microsystems - Beijing China }
4083dd1de374Slin wang - Sun Microsystems - Beijing China 
4084dd1de374Slin wang - Sun Microsystems - Beijing China void
4085dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_reset_tsf(struct ath_hal *ah)
4086dd1de374Slin wang - Sun Microsystems - Beijing China {
4087dd1de374Slin wang - Sun Microsystems - Beijing China 	int count;
4088dd1de374Slin wang - Sun Microsystems - Beijing China 
4089dd1de374Slin wang - Sun Microsystems - Beijing China 	count = 0;
4090dd1de374Slin wang - Sun Microsystems - Beijing China 	while (REG_READ(ah, AR_SLP32_MODE) & AR_SLP32_TSF_WRITE_STATUS) {
4091dd1de374Slin wang - Sun Microsystems - Beijing China 		count++;
4092dd1de374Slin wang - Sun Microsystems - Beijing China 		if (count > 10) {
4093dd1de374Slin wang - Sun Microsystems - Beijing China 			ARN_DBG((ARN_DBG_HW, "arn: "
4094dd1de374Slin wang - Sun Microsystems - Beijing China 			    "%s: AR_SLP32_TSF_WRITE_STATUS limit exceeded\n",
4095dd1de374Slin wang - Sun Microsystems - Beijing China 			    __func__));
4096dd1de374Slin wang - Sun Microsystems - Beijing China 
4097dd1de374Slin wang - Sun Microsystems - Beijing China 			break;
4098dd1de374Slin wang - Sun Microsystems - Beijing China 		}
4099dd1de374Slin wang - Sun Microsystems - Beijing China 		drv_usecwait(10);
4100dd1de374Slin wang - Sun Microsystems - Beijing China 	}
4101dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
4102dd1de374Slin wang - Sun Microsystems - Beijing China }
4103dd1de374Slin wang - Sun Microsystems - Beijing China 
4104dd1de374Slin wang - Sun Microsystems - Beijing China boolean_t
4105dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_set_tsfadjust(struct ath_hal *ah, uint32_t setting)
4106dd1de374Slin wang - Sun Microsystems - Beijing China {
4107dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
4108dd1de374Slin wang - Sun Microsystems - Beijing China 
4109dd1de374Slin wang - Sun Microsystems - Beijing China 	if (setting)
4110dd1de374Slin wang - Sun Microsystems - Beijing China 		ahp->ah_miscMode |= AR_PCU_TX_ADD_TSF;
4111dd1de374Slin wang - Sun Microsystems - Beijing China 	else
4112dd1de374Slin wang - Sun Microsystems - Beijing China 		ahp->ah_miscMode &= ~AR_PCU_TX_ADD_TSF;
4113dd1de374Slin wang - Sun Microsystems - Beijing China 
4114dd1de374Slin wang - Sun Microsystems - Beijing China 	return (B_TRUE);
4115dd1de374Slin wang - Sun Microsystems - Beijing China }
4116dd1de374Slin wang - Sun Microsystems - Beijing China 
4117dd1de374Slin wang - Sun Microsystems - Beijing China boolean_t
4118dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_setslottime(struct ath_hal *ah, uint32_t us)
4119dd1de374Slin wang - Sun Microsystems - Beijing China {
4120dd1de374Slin wang - Sun Microsystems - Beijing China 	struct ath_hal_5416 *ahp = AH5416(ah);
4121dd1de374Slin wang - Sun Microsystems - Beijing China 
4122dd1de374Slin wang - Sun Microsystems - Beijing China 	if (us < ATH9K_SLOT_TIME_9 || us > ath9k_hw_mac_to_usec(ah, 0xffff)) {
4123dd1de374Slin wang - Sun Microsystems - Beijing China 		ARN_DBG((ARN_DBG_HW, "arn: "
4124dd1de374Slin wang - Sun Microsystems - Beijing China 		    "%s: bad slot time %u\n",  __func__, us));
4125dd1de374Slin wang - Sun Microsystems - Beijing China 
4126dd1de374Slin wang - Sun Microsystems - Beijing China 		ahp->ah_slottime = (uint32_t)-1;
4127dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_FALSE);
4128dd1de374Slin wang - Sun Microsystems - Beijing China 	} else {
4129dd1de374Slin wang - Sun Microsystems - Beijing China 		REG_WRITE(ah, AR_D_GBL_IFS_SLOT, ath9k_hw_mac_to_clks(ah, us));
4130dd1de374Slin wang - Sun Microsystems - Beijing China 		ahp->ah_slottime = us;
4131dd1de374Slin wang - Sun Microsystems - Beijing China 		return (B_TRUE);
4132dd1de374Slin wang - Sun Microsystems - Beijing China 	}
4133dd1de374Slin wang - Sun Microsystems - Beijing China }
4134dd1de374Slin wang - Sun Microsystems - Beijing China 
4135dd1de374Slin wang - Sun Microsystems - Beijing China void
4136dd1de374Slin wang - Sun Microsystems - Beijing China ath9k_hw_set11nmac2040(struct ath_hal *ah, enum ath9k_ht_macmode mode)
4137dd1de374Slin wang - Sun Microsystems - Beijing China {
4138dd1de374Slin wang - Sun Microsystems - Beijing China 	uint32_t macmode;
4139dd1de374Slin wang - Sun Microsystems - Beijing China 
4140dd1de374Slin wang - Sun Microsystems - Beijing China 	if (mode == ATH9K_HT_MACMODE_2040 &&
4141dd1de374Slin wang - Sun Microsystems - Beijing China 	    !ah->ah_config.cwm_ignore_extcca)
4142dd1de374Slin wang - Sun Microsystems - Beijing China 		macmode = AR_2040_JOINED_RX_CLEAR;
4143dd1de374Slin wang - Sun Microsystems - Beijing China 	else
4144dd1de374Slin wang - Sun Microsystems - Beijing China 		macmode = 0;
4145dd1de374Slin wang - Sun Microsystems - Beijing China 
4146dd1de374Slin wang - Sun Microsystems - Beijing China 	REG_WRITE(ah, AR_2040_MODE, macmode);
4147dd1de374Slin wang - Sun Microsystems - Beijing China }
4148