1*572ff6f6SMatthew Dillon /*
2*572ff6f6SMatthew Dillon  * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
3*572ff6f6SMatthew Dillon  * Copyright (c) 2002-2008 Atheros Communications, Inc.
4*572ff6f6SMatthew Dillon  *
5*572ff6f6SMatthew Dillon  * Permission to use, copy, modify, and/or distribute this software for any
6*572ff6f6SMatthew Dillon  * purpose with or without fee is hereby granted, provided that the above
7*572ff6f6SMatthew Dillon  * copyright notice and this permission notice appear in all copies.
8*572ff6f6SMatthew Dillon  *
9*572ff6f6SMatthew Dillon  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10*572ff6f6SMatthew Dillon  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11*572ff6f6SMatthew Dillon  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12*572ff6f6SMatthew Dillon  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13*572ff6f6SMatthew Dillon  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14*572ff6f6SMatthew Dillon  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15*572ff6f6SMatthew Dillon  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16*572ff6f6SMatthew Dillon  *
17*572ff6f6SMatthew Dillon  * $FreeBSD$
18*572ff6f6SMatthew Dillon  */
19*572ff6f6SMatthew Dillon #include "opt_ah.h"
20*572ff6f6SMatthew Dillon 
21*572ff6f6SMatthew Dillon #include "ah.h"
22*572ff6f6SMatthew Dillon #include "ah_internal.h"
23*572ff6f6SMatthew Dillon #include "ah_devid.h"
24*572ff6f6SMatthew Dillon #include "ah_desc.h"                    /* NB: for HAL_PHYERR* */
25*572ff6f6SMatthew Dillon 
26*572ff6f6SMatthew Dillon #include "ar5416/ar5416.h"
27*572ff6f6SMatthew Dillon #include "ar5416/ar5416reg.h"
28*572ff6f6SMatthew Dillon #include "ar5416/ar5416phy.h"
29*572ff6f6SMatthew Dillon 
30*572ff6f6SMatthew Dillon #include "ah_eeprom_v14.h"	/* for owl_get_ntxchains() */
31*572ff6f6SMatthew Dillon 
32*572ff6f6SMatthew Dillon /*
33*572ff6f6SMatthew Dillon  * Return the wireless modes (a,b,g,n,t) supported by hardware.
34*572ff6f6SMatthew Dillon  *
35*572ff6f6SMatthew Dillon  * This value is what is actually supported by the hardware
36*572ff6f6SMatthew Dillon  * and is unaffected by regulatory/country code settings.
37*572ff6f6SMatthew Dillon  *
38*572ff6f6SMatthew Dillon  */
39*572ff6f6SMatthew Dillon u_int
ar5416GetWirelessModes(struct ath_hal * ah)40*572ff6f6SMatthew Dillon ar5416GetWirelessModes(struct ath_hal *ah)
41*572ff6f6SMatthew Dillon {
42*572ff6f6SMatthew Dillon 	u_int mode;
43*572ff6f6SMatthew Dillon 	struct ath_hal_private *ahpriv = AH_PRIVATE(ah);
44*572ff6f6SMatthew Dillon 	HAL_CAPABILITIES *pCap = &ahpriv->ah_caps;
45*572ff6f6SMatthew Dillon 
46*572ff6f6SMatthew Dillon 	mode = ar5212GetWirelessModes(ah);
47*572ff6f6SMatthew Dillon 
48*572ff6f6SMatthew Dillon 	/* Only enable HT modes if the NIC supports HT */
49*572ff6f6SMatthew Dillon 	if (pCap->halHTSupport == AH_TRUE && (mode & HAL_MODE_11A))
50*572ff6f6SMatthew Dillon 		mode |= HAL_MODE_11NA_HT20
51*572ff6f6SMatthew Dillon 		     |  HAL_MODE_11NA_HT40PLUS
52*572ff6f6SMatthew Dillon 		     |  HAL_MODE_11NA_HT40MINUS
53*572ff6f6SMatthew Dillon 		     ;
54*572ff6f6SMatthew Dillon 	if (pCap->halHTSupport == AH_TRUE && (mode & HAL_MODE_11G))
55*572ff6f6SMatthew Dillon 		mode |= HAL_MODE_11NG_HT20
56*572ff6f6SMatthew Dillon 		     |  HAL_MODE_11NG_HT40PLUS
57*572ff6f6SMatthew Dillon 		     |  HAL_MODE_11NG_HT40MINUS
58*572ff6f6SMatthew Dillon 		     ;
59*572ff6f6SMatthew Dillon 	return mode;
60*572ff6f6SMatthew Dillon }
61*572ff6f6SMatthew Dillon 
62*572ff6f6SMatthew Dillon /*
63*572ff6f6SMatthew Dillon  * Change the LED blinking pattern to correspond to the connectivity
64*572ff6f6SMatthew Dillon  */
65*572ff6f6SMatthew Dillon void
ar5416SetLedState(struct ath_hal * ah,HAL_LED_STATE state)66*572ff6f6SMatthew Dillon ar5416SetLedState(struct ath_hal *ah, HAL_LED_STATE state)
67*572ff6f6SMatthew Dillon {
68*572ff6f6SMatthew Dillon 	static const uint32_t ledbits[8] = {
69*572ff6f6SMatthew Dillon 		AR_MAC_LED_ASSOC_NONE,		/* HAL_LED_INIT */
70*572ff6f6SMatthew Dillon 		AR_MAC_LED_ASSOC_PEND,		/* HAL_LED_SCAN */
71*572ff6f6SMatthew Dillon 		AR_MAC_LED_ASSOC_PEND,		/* HAL_LED_AUTH */
72*572ff6f6SMatthew Dillon 		AR_MAC_LED_ASSOC_ACTIVE,	/* HAL_LED_ASSOC*/
73*572ff6f6SMatthew Dillon 		AR_MAC_LED_ASSOC_ACTIVE,	/* HAL_LED_RUN */
74*572ff6f6SMatthew Dillon 		AR_MAC_LED_ASSOC_NONE,
75*572ff6f6SMatthew Dillon 		AR_MAC_LED_ASSOC_NONE,
76*572ff6f6SMatthew Dillon 		AR_MAC_LED_ASSOC_NONE,
77*572ff6f6SMatthew Dillon 	};
78*572ff6f6SMatthew Dillon 
79*572ff6f6SMatthew Dillon 	if (AR_SREV_HOWL(ah))
80*572ff6f6SMatthew Dillon 		return;
81*572ff6f6SMatthew Dillon 
82*572ff6f6SMatthew Dillon 	/*
83*572ff6f6SMatthew Dillon 	 * Set the blink operating mode.
84*572ff6f6SMatthew Dillon 	 */
85*572ff6f6SMatthew Dillon 	OS_REG_RMW_FIELD(ah, AR_MAC_LED,
86*572ff6f6SMatthew Dillon 	    AR_MAC_LED_ASSOC, ledbits[state & 0x7]);
87*572ff6f6SMatthew Dillon 
88*572ff6f6SMatthew Dillon 	/* XXX Blink slow mode? */
89*572ff6f6SMatthew Dillon 	/* XXX Blink threshold? */
90*572ff6f6SMatthew Dillon 	/* XXX Blink sleep hystersis? */
91*572ff6f6SMatthew Dillon 
92*572ff6f6SMatthew Dillon 	/*
93*572ff6f6SMatthew Dillon 	 * Set the LED blink configuration to be proportional
94*572ff6f6SMatthew Dillon 	 * to the current TX and RX filter bytes.  (Ie, RX'ed
95*572ff6f6SMatthew Dillon 	 * frames that don't match the filter are ignored.)
96*572ff6f6SMatthew Dillon 	 * This means that higher TX/RX throughput will result
97*572ff6f6SMatthew Dillon 	 * in the blink rate increasing.
98*572ff6f6SMatthew Dillon 	 */
99*572ff6f6SMatthew Dillon 	OS_REG_RMW_FIELD(ah, AR_MAC_LED, AR_MAC_LED_MODE,
100*572ff6f6SMatthew Dillon 	    AR_MAC_LED_MODE_PROP);
101*572ff6f6SMatthew Dillon }
102*572ff6f6SMatthew Dillon 
103*572ff6f6SMatthew Dillon /*
104*572ff6f6SMatthew Dillon  * Get the current hardware tsf for stamlme
105*572ff6f6SMatthew Dillon  */
106*572ff6f6SMatthew Dillon uint64_t
ar5416GetTsf64(struct ath_hal * ah)107*572ff6f6SMatthew Dillon ar5416GetTsf64(struct ath_hal *ah)
108*572ff6f6SMatthew Dillon {
109*572ff6f6SMatthew Dillon 	uint32_t low1, low2, u32;
110*572ff6f6SMatthew Dillon 
111*572ff6f6SMatthew Dillon 	/* sync multi-word read */
112*572ff6f6SMatthew Dillon 	low1 = OS_REG_READ(ah, AR_TSF_L32);
113*572ff6f6SMatthew Dillon 	u32 = OS_REG_READ(ah, AR_TSF_U32);
114*572ff6f6SMatthew Dillon 	low2 = OS_REG_READ(ah, AR_TSF_L32);
115*572ff6f6SMatthew Dillon 	if (low2 < low1) {	/* roll over */
116*572ff6f6SMatthew Dillon 		/*
117*572ff6f6SMatthew Dillon 		 * If we are not preempted this will work.  If we are
118*572ff6f6SMatthew Dillon 		 * then we re-reading AR_TSF_U32 does no good as the
119*572ff6f6SMatthew Dillon 		 * low bits will be meaningless.  Likewise reading
120*572ff6f6SMatthew Dillon 		 * L32, U32, U32, then comparing the last two reads
121*572ff6f6SMatthew Dillon 		 * to check for rollover doesn't help if preempted--so
122*572ff6f6SMatthew Dillon 		 * we take this approach as it costs one less PCI read
123*572ff6f6SMatthew Dillon 		 * which can be noticeable when doing things like
124*572ff6f6SMatthew Dillon 		 * timestamping packets in monitor mode.
125*572ff6f6SMatthew Dillon 		 */
126*572ff6f6SMatthew Dillon 		u32++;
127*572ff6f6SMatthew Dillon 	}
128*572ff6f6SMatthew Dillon 	return (((uint64_t) u32) << 32) | ((uint64_t) low2);
129*572ff6f6SMatthew Dillon }
130*572ff6f6SMatthew Dillon 
131*572ff6f6SMatthew Dillon /*
132*572ff6f6SMatthew Dillon  * Update the TSF.
133*572ff6f6SMatthew Dillon  *
134*572ff6f6SMatthew Dillon  * The full TSF is only updated once the upper 32 bits have
135*572ff6f6SMatthew Dillon  * been written.  Writing only the lower 32 bits of the TSF
136*572ff6f6SMatthew Dillon  * will not actually correctly update the TSF.
137*572ff6f6SMatthew Dillon  *
138*572ff6f6SMatthew Dillon  * The #if 0'ed code is to check whether the previous TSF
139*572ff6f6SMatthew Dillon  * reset or write has completed before writing to the
140*572ff6f6SMatthew Dillon  * TSF.  Strictly speaking, it should be also checked before
141*572ff6f6SMatthew Dillon  * reading the TSF as the write/reset may not have completed.
142*572ff6f6SMatthew Dillon  */
143*572ff6f6SMatthew Dillon void
ar5416SetTsf64(struct ath_hal * ah,uint64_t tsf64)144*572ff6f6SMatthew Dillon ar5416SetTsf64(struct ath_hal *ah, uint64_t tsf64)
145*572ff6f6SMatthew Dillon {
146*572ff6f6SMatthew Dillon 	/* XXX check if this is correct! */
147*572ff6f6SMatthew Dillon #if 0
148*572ff6f6SMatthew Dillon 	int i;
149*572ff6f6SMatthew Dillon 	uint32_t v;
150*572ff6f6SMatthew Dillon 
151*572ff6f6SMatthew Dillon 	for (i = 0; i < 10; i++) {
152*572ff6f6SMatthew Dillon 		v = OS_REG_READ(ah, AR_SLP32_MODE);
153*572ff6f6SMatthew Dillon 		if ((v & AR_SLP32_TSF_WRITE_STATUS) == 0)
154*572ff6f6SMatthew Dillon 			break;
155*572ff6f6SMatthew Dillon 		OS_DELAY(10);
156*572ff6f6SMatthew Dillon 	}
157*572ff6f6SMatthew Dillon 	if (i == 10)
158*572ff6f6SMatthew Dillon 		ath_hal_printf(ah, "%s: couldn't slew things right!\n", __func__);
159*572ff6f6SMatthew Dillon #endif
160*572ff6f6SMatthew Dillon 
161*572ff6f6SMatthew Dillon 	OS_REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
162*572ff6f6SMatthew Dillon 	OS_REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
163*572ff6f6SMatthew Dillon }
164*572ff6f6SMatthew Dillon 
165*572ff6f6SMatthew Dillon /*
166*572ff6f6SMatthew Dillon  * Reset the current hardware tsf for stamlme.
167*572ff6f6SMatthew Dillon  */
168*572ff6f6SMatthew Dillon void
ar5416ResetTsf(struct ath_hal * ah)169*572ff6f6SMatthew Dillon ar5416ResetTsf(struct ath_hal *ah)
170*572ff6f6SMatthew Dillon {
171*572ff6f6SMatthew Dillon 	uint32_t v;
172*572ff6f6SMatthew Dillon 	int i;
173*572ff6f6SMatthew Dillon 
174*572ff6f6SMatthew Dillon 	for (i = 0; i < 10; i++) {
175*572ff6f6SMatthew Dillon 		v = OS_REG_READ(ah, AR_SLP32_MODE);
176*572ff6f6SMatthew Dillon 		if ((v & AR_SLP32_TSF_WRITE_STATUS) == 0)
177*572ff6f6SMatthew Dillon 			break;
178*572ff6f6SMatthew Dillon 		OS_DELAY(10);
179*572ff6f6SMatthew Dillon 	}
180*572ff6f6SMatthew Dillon 	OS_REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
181*572ff6f6SMatthew Dillon }
182*572ff6f6SMatthew Dillon 
183*572ff6f6SMatthew Dillon uint32_t
ar5416GetCurRssi(struct ath_hal * ah)184*572ff6f6SMatthew Dillon ar5416GetCurRssi(struct ath_hal *ah)
185*572ff6f6SMatthew Dillon {
186*572ff6f6SMatthew Dillon 	if (AR_SREV_OWL(ah))
187*572ff6f6SMatthew Dillon 		return (OS_REG_READ(ah, AR_PHY_CURRENT_RSSI) & 0xff);
188*572ff6f6SMatthew Dillon 	return (OS_REG_READ(ah, AR9130_PHY_CURRENT_RSSI) & 0xff);
189*572ff6f6SMatthew Dillon }
190*572ff6f6SMatthew Dillon 
191*572ff6f6SMatthew Dillon HAL_BOOL
ar5416SetAntennaSwitch(struct ath_hal * ah,HAL_ANT_SETTING settings)192*572ff6f6SMatthew Dillon ar5416SetAntennaSwitch(struct ath_hal *ah, HAL_ANT_SETTING settings)
193*572ff6f6SMatthew Dillon {
194*572ff6f6SMatthew Dillon 	return AH_TRUE;
195*572ff6f6SMatthew Dillon }
196*572ff6f6SMatthew Dillon 
197*572ff6f6SMatthew Dillon /* Setup decompression for given key index */
198*572ff6f6SMatthew Dillon HAL_BOOL
ar5416SetDecompMask(struct ath_hal * ah,uint16_t keyidx,int en)199*572ff6f6SMatthew Dillon ar5416SetDecompMask(struct ath_hal *ah, uint16_t keyidx, int en)
200*572ff6f6SMatthew Dillon {
201*572ff6f6SMatthew Dillon 	return AH_TRUE;
202*572ff6f6SMatthew Dillon }
203*572ff6f6SMatthew Dillon 
204*572ff6f6SMatthew Dillon /* Setup coverage class */
205*572ff6f6SMatthew Dillon void
ar5416SetCoverageClass(struct ath_hal * ah,uint8_t coverageclass,int now)206*572ff6f6SMatthew Dillon ar5416SetCoverageClass(struct ath_hal *ah, uint8_t coverageclass, int now)
207*572ff6f6SMatthew Dillon {
208*572ff6f6SMatthew Dillon 
209*572ff6f6SMatthew Dillon 	ar5212SetCoverageClass(ah, coverageclass, now);
210*572ff6f6SMatthew Dillon }
211*572ff6f6SMatthew Dillon 
212*572ff6f6SMatthew Dillon /*
213*572ff6f6SMatthew Dillon  * Return the busy for rx_frame, rx_clear, and tx_frame
214*572ff6f6SMatthew Dillon  */
215*572ff6f6SMatthew Dillon HAL_BOOL
ar5416GetMibCycleCounts(struct ath_hal * ah,HAL_SURVEY_SAMPLE * hsample)216*572ff6f6SMatthew Dillon ar5416GetMibCycleCounts(struct ath_hal *ah, HAL_SURVEY_SAMPLE *hsample)
217*572ff6f6SMatthew Dillon {
218*572ff6f6SMatthew Dillon 	struct ath_hal_5416 *ahp = AH5416(ah);
219*572ff6f6SMatthew Dillon 	u_int32_t good = AH_TRUE;
220*572ff6f6SMatthew Dillon 
221*572ff6f6SMatthew Dillon 	/* XXX freeze/unfreeze mib counters */
222*572ff6f6SMatthew Dillon 	uint32_t rc = OS_REG_READ(ah, AR_RCCNT);
223*572ff6f6SMatthew Dillon 	uint32_t ec = OS_REG_READ(ah, AR_EXTRCCNT);
224*572ff6f6SMatthew Dillon 	uint32_t rf = OS_REG_READ(ah, AR_RFCNT);
225*572ff6f6SMatthew Dillon 	uint32_t tf = OS_REG_READ(ah, AR_TFCNT);
226*572ff6f6SMatthew Dillon 	uint32_t cc = OS_REG_READ(ah, AR_CCCNT); /* read cycles last */
227*572ff6f6SMatthew Dillon 
228*572ff6f6SMatthew Dillon 	if (ahp->ah_cycleCount == 0 || ahp->ah_cycleCount > cc) {
229*572ff6f6SMatthew Dillon 		/*
230*572ff6f6SMatthew Dillon 		 * Cycle counter wrap (or initial call); it's not possible
231*572ff6f6SMatthew Dillon 		 * to accurately calculate a value because the registers
232*572ff6f6SMatthew Dillon 		 * right shift rather than wrap--so punt and return 0.
233*572ff6f6SMatthew Dillon 		 */
234*572ff6f6SMatthew Dillon 		HALDEBUG(ah, HAL_DEBUG_ANY,
235*572ff6f6SMatthew Dillon 			    "%s: cycle counter wrap. ExtBusy = 0\n", __func__);
236*572ff6f6SMatthew Dillon 			good = AH_FALSE;
237*572ff6f6SMatthew Dillon 	} else {
238*572ff6f6SMatthew Dillon 		hsample->cycle_count = cc - ahp->ah_cycleCount;
239*572ff6f6SMatthew Dillon 		hsample->chan_busy = rc - ahp->ah_ctlBusy;
240*572ff6f6SMatthew Dillon 		hsample->ext_chan_busy = ec - ahp->ah_extBusy;
241*572ff6f6SMatthew Dillon 		hsample->rx_busy = rf - ahp->ah_rxBusy;
242*572ff6f6SMatthew Dillon 		hsample->tx_busy = tf - ahp->ah_txBusy;
243*572ff6f6SMatthew Dillon 	}
244*572ff6f6SMatthew Dillon 
245*572ff6f6SMatthew Dillon 	/*
246*572ff6f6SMatthew Dillon 	 * Keep a copy of the MIB results so the next sample has something
247*572ff6f6SMatthew Dillon 	 * to work from.
248*572ff6f6SMatthew Dillon 	 */
249*572ff6f6SMatthew Dillon 	ahp->ah_cycleCount = cc;
250*572ff6f6SMatthew Dillon 	ahp->ah_rxBusy = rf;
251*572ff6f6SMatthew Dillon 	ahp->ah_ctlBusy = rc;
252*572ff6f6SMatthew Dillon 	ahp->ah_txBusy = tf;
253*572ff6f6SMatthew Dillon 	ahp->ah_extBusy = ec;
254*572ff6f6SMatthew Dillon 
255*572ff6f6SMatthew Dillon 	return (good);
256*572ff6f6SMatthew Dillon }
257*572ff6f6SMatthew Dillon 
258*572ff6f6SMatthew Dillon /*
259*572ff6f6SMatthew Dillon  * Setup the TX/RX chainmasks - this needs to be done before a call
260*572ff6f6SMatthew Dillon  * to the reset method as it doesn't update the hardware.
261*572ff6f6SMatthew Dillon  */
262*572ff6f6SMatthew Dillon void
ar5416SetChainMasks(struct ath_hal * ah,uint32_t tx_chainmask,uint32_t rx_chainmask)263*572ff6f6SMatthew Dillon ar5416SetChainMasks(struct ath_hal *ah, uint32_t tx_chainmask,
264*572ff6f6SMatthew Dillon     uint32_t rx_chainmask)
265*572ff6f6SMatthew Dillon {
266*572ff6f6SMatthew Dillon 	HAL_CAPABILITIES *pCap = &AH_PRIVATE(ah)->ah_caps;
267*572ff6f6SMatthew Dillon 
268*572ff6f6SMatthew Dillon 	AH5416(ah)->ah_tx_chainmask = tx_chainmask & pCap->halTxChainMask;
269*572ff6f6SMatthew Dillon 	AH5416(ah)->ah_rx_chainmask = rx_chainmask & pCap->halRxChainMask;
270*572ff6f6SMatthew Dillon }
271*572ff6f6SMatthew Dillon 
272*572ff6f6SMatthew Dillon /*
273*572ff6f6SMatthew Dillon  * Return approximation of extension channel busy over an time interval
274*572ff6f6SMatthew Dillon  * 0% (clear) -> 100% (busy)
275*572ff6f6SMatthew Dillon  *
276*572ff6f6SMatthew Dillon  * XXX TODO: update this to correctly sample all the counters,
277*572ff6f6SMatthew Dillon  *           rather than a subset of it.
278*572ff6f6SMatthew Dillon  */
279*572ff6f6SMatthew Dillon uint32_t
ar5416Get11nExtBusy(struct ath_hal * ah)280*572ff6f6SMatthew Dillon ar5416Get11nExtBusy(struct ath_hal *ah)
281*572ff6f6SMatthew Dillon {
282*572ff6f6SMatthew Dillon     struct ath_hal_5416 *ahp = AH5416(ah);
283*572ff6f6SMatthew Dillon     uint32_t busy; /* percentage */
284*572ff6f6SMatthew Dillon     uint32_t cycleCount, ctlBusy, extBusy;
285*572ff6f6SMatthew Dillon 
286*572ff6f6SMatthew Dillon     ctlBusy = OS_REG_READ(ah, AR_RCCNT);
287*572ff6f6SMatthew Dillon     extBusy = OS_REG_READ(ah, AR_EXTRCCNT);
288*572ff6f6SMatthew Dillon     cycleCount = OS_REG_READ(ah, AR_CCCNT);
289*572ff6f6SMatthew Dillon 
290*572ff6f6SMatthew Dillon     if (ahp->ah_cycleCount == 0 || ahp->ah_cycleCount > cycleCount) {
291*572ff6f6SMatthew Dillon         /*
292*572ff6f6SMatthew Dillon          * Cycle counter wrap (or initial call); it's not possible
293*572ff6f6SMatthew Dillon          * to accurately calculate a value because the registers
294*572ff6f6SMatthew Dillon          * right shift rather than wrap--so punt and return 0.
295*572ff6f6SMatthew Dillon          */
296*572ff6f6SMatthew Dillon         busy = 0;
297*572ff6f6SMatthew Dillon         HALDEBUG(ah, HAL_DEBUG_ANY, "%s: cycle counter wrap. ExtBusy = 0\n",
298*572ff6f6SMatthew Dillon 	    __func__);
299*572ff6f6SMatthew Dillon 
300*572ff6f6SMatthew Dillon     } else {
301*572ff6f6SMatthew Dillon         uint32_t cycleDelta = cycleCount - ahp->ah_cycleCount;
302*572ff6f6SMatthew Dillon         uint32_t ctlBusyDelta = ctlBusy - ahp->ah_ctlBusy;
303*572ff6f6SMatthew Dillon         uint32_t extBusyDelta = extBusy - ahp->ah_extBusy;
304*572ff6f6SMatthew Dillon         uint32_t ctlClearDelta = 0;
305*572ff6f6SMatthew Dillon 
306*572ff6f6SMatthew Dillon         /* Compute control channel rxclear.
307*572ff6f6SMatthew Dillon          * The cycle delta may be less than the control channel delta.
308*572ff6f6SMatthew Dillon          * This could be solved by freezing the timers (or an atomic read,
309*572ff6f6SMatthew Dillon          * if one was available). Checking for the condition should be
310*572ff6f6SMatthew Dillon          * sufficient.
311*572ff6f6SMatthew Dillon          */
312*572ff6f6SMatthew Dillon         if (cycleDelta > ctlBusyDelta) {
313*572ff6f6SMatthew Dillon             ctlClearDelta = cycleDelta - ctlBusyDelta;
314*572ff6f6SMatthew Dillon         }
315*572ff6f6SMatthew Dillon 
316*572ff6f6SMatthew Dillon         /* Compute ratio of extension channel busy to control channel clear
317*572ff6f6SMatthew Dillon          * as an approximation to extension channel cleanliness.
318*572ff6f6SMatthew Dillon          *
319*572ff6f6SMatthew Dillon          * According to the hardware folks, ext rxclear is undefined
320*572ff6f6SMatthew Dillon          * if the ctrl rxclear is de-asserted (i.e. busy)
321*572ff6f6SMatthew Dillon          */
322*572ff6f6SMatthew Dillon         if (ctlClearDelta) {
323*572ff6f6SMatthew Dillon             busy = (extBusyDelta * 100) / ctlClearDelta;
324*572ff6f6SMatthew Dillon         } else {
325*572ff6f6SMatthew Dillon             busy = 100;
326*572ff6f6SMatthew Dillon         }
327*572ff6f6SMatthew Dillon         if (busy > 100) {
328*572ff6f6SMatthew Dillon             busy = 100;
329*572ff6f6SMatthew Dillon         }
330*572ff6f6SMatthew Dillon #if 0
331*572ff6f6SMatthew Dillon         HALDEBUG(ah, HAL_DEBUG_ANY, "%s: cycleDelta 0x%x, ctlBusyDelta 0x%x, "
332*572ff6f6SMatthew Dillon              "extBusyDelta 0x%x, ctlClearDelta 0x%x, "
333*572ff6f6SMatthew Dillon              "busy %d\n",
334*572ff6f6SMatthew Dillon               __func__, cycleDelta, ctlBusyDelta, extBusyDelta, ctlClearDelta, busy);
335*572ff6f6SMatthew Dillon #endif
336*572ff6f6SMatthew Dillon     }
337*572ff6f6SMatthew Dillon 
338*572ff6f6SMatthew Dillon     ahp->ah_cycleCount = cycleCount;
339*572ff6f6SMatthew Dillon     ahp->ah_ctlBusy = ctlBusy;
340*572ff6f6SMatthew Dillon     ahp->ah_extBusy = extBusy;
341*572ff6f6SMatthew Dillon 
342*572ff6f6SMatthew Dillon     return busy;
343*572ff6f6SMatthew Dillon }
344*572ff6f6SMatthew Dillon 
345*572ff6f6SMatthew Dillon /*
346*572ff6f6SMatthew Dillon  * Configure 20/40 operation
347*572ff6f6SMatthew Dillon  *
348*572ff6f6SMatthew Dillon  * 20/40 = joint rx clear (control and extension)
349*572ff6f6SMatthew Dillon  * 20    = rx clear (control)
350*572ff6f6SMatthew Dillon  *
351*572ff6f6SMatthew Dillon  * - NOTE: must stop MAC (tx) and requeue 40 MHz packets as 20 MHz when changing
352*572ff6f6SMatthew Dillon  *         from 20/40 => 20 only
353*572ff6f6SMatthew Dillon  */
354*572ff6f6SMatthew Dillon void
ar5416Set11nMac2040(struct ath_hal * ah,HAL_HT_MACMODE mode)355*572ff6f6SMatthew Dillon ar5416Set11nMac2040(struct ath_hal *ah, HAL_HT_MACMODE mode)
356*572ff6f6SMatthew Dillon {
357*572ff6f6SMatthew Dillon     uint32_t macmode;
358*572ff6f6SMatthew Dillon 
359*572ff6f6SMatthew Dillon     /* Configure MAC for 20/40 operation */
360*572ff6f6SMatthew Dillon     if (mode == HAL_HT_MACMODE_2040) {
361*572ff6f6SMatthew Dillon         macmode = AR_2040_JOINED_RX_CLEAR;
362*572ff6f6SMatthew Dillon     } else {
363*572ff6f6SMatthew Dillon         macmode = 0;
364*572ff6f6SMatthew Dillon     }
365*572ff6f6SMatthew Dillon     OS_REG_WRITE(ah, AR_2040_MODE, macmode);
366*572ff6f6SMatthew Dillon }
367*572ff6f6SMatthew Dillon 
368*572ff6f6SMatthew Dillon /*
369*572ff6f6SMatthew Dillon  * Get Rx clear (control/extension channel)
370*572ff6f6SMatthew Dillon  *
371*572ff6f6SMatthew Dillon  * Returns active low (busy) for ctrl/ext channel
372*572ff6f6SMatthew Dillon  * Owl 2.0
373*572ff6f6SMatthew Dillon  */
374*572ff6f6SMatthew Dillon HAL_HT_RXCLEAR
ar5416Get11nRxClear(struct ath_hal * ah)375*572ff6f6SMatthew Dillon ar5416Get11nRxClear(struct ath_hal *ah)
376*572ff6f6SMatthew Dillon {
377*572ff6f6SMatthew Dillon     HAL_HT_RXCLEAR rxclear = 0;
378*572ff6f6SMatthew Dillon     uint32_t val;
379*572ff6f6SMatthew Dillon 
380*572ff6f6SMatthew Dillon     val = OS_REG_READ(ah, AR_DIAG_SW);
381*572ff6f6SMatthew Dillon 
382*572ff6f6SMatthew Dillon     /* control channel */
383*572ff6f6SMatthew Dillon     if (val & AR_DIAG_RXCLEAR_CTL_LOW) {
384*572ff6f6SMatthew Dillon         rxclear |= HAL_RX_CLEAR_CTL_LOW;
385*572ff6f6SMatthew Dillon     }
386*572ff6f6SMatthew Dillon     /* extension channel */
387*572ff6f6SMatthew Dillon     if (val & AR_DIAG_RXCLEAR_EXT_LOW) {
388*572ff6f6SMatthew Dillon         rxclear |= HAL_RX_CLEAR_EXT_LOW;
389*572ff6f6SMatthew Dillon     }
390*572ff6f6SMatthew Dillon     return rxclear;
391*572ff6f6SMatthew Dillon }
392*572ff6f6SMatthew Dillon 
393*572ff6f6SMatthew Dillon /*
394*572ff6f6SMatthew Dillon  * Set Rx clear (control/extension channel)
395*572ff6f6SMatthew Dillon  *
396*572ff6f6SMatthew Dillon  * Useful for forcing the channel to appear busy for
397*572ff6f6SMatthew Dillon  * debugging/diagnostics
398*572ff6f6SMatthew Dillon  * Owl 2.0
399*572ff6f6SMatthew Dillon  */
400*572ff6f6SMatthew Dillon void
ar5416Set11nRxClear(struct ath_hal * ah,HAL_HT_RXCLEAR rxclear)401*572ff6f6SMatthew Dillon ar5416Set11nRxClear(struct ath_hal *ah, HAL_HT_RXCLEAR rxclear)
402*572ff6f6SMatthew Dillon {
403*572ff6f6SMatthew Dillon     /* control channel */
404*572ff6f6SMatthew Dillon     if (rxclear & HAL_RX_CLEAR_CTL_LOW) {
405*572ff6f6SMatthew Dillon         OS_REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RXCLEAR_CTL_LOW);
406*572ff6f6SMatthew Dillon     } else {
407*572ff6f6SMatthew Dillon         OS_REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_RXCLEAR_CTL_LOW);
408*572ff6f6SMatthew Dillon     }
409*572ff6f6SMatthew Dillon     /* extension channel */
410*572ff6f6SMatthew Dillon     if (rxclear & HAL_RX_CLEAR_EXT_LOW) {
411*572ff6f6SMatthew Dillon         OS_REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RXCLEAR_EXT_LOW);
412*572ff6f6SMatthew Dillon     } else {
413*572ff6f6SMatthew Dillon         OS_REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_RXCLEAR_EXT_LOW);
414*572ff6f6SMatthew Dillon     }
415*572ff6f6SMatthew Dillon }
416*572ff6f6SMatthew Dillon 
417*572ff6f6SMatthew Dillon /* XXX shouldn't be here! */
418*572ff6f6SMatthew Dillon #define	TU_TO_USEC(_tu)		((_tu) << 10)
419*572ff6f6SMatthew Dillon 
420*572ff6f6SMatthew Dillon HAL_STATUS
ar5416SetQuiet(struct ath_hal * ah,uint32_t period,uint32_t duration,uint32_t nextStart,HAL_QUIET_FLAG flag)421*572ff6f6SMatthew Dillon ar5416SetQuiet(struct ath_hal *ah, uint32_t period, uint32_t duration,
422*572ff6f6SMatthew Dillon     uint32_t nextStart, HAL_QUIET_FLAG flag)
423*572ff6f6SMatthew Dillon {
424*572ff6f6SMatthew Dillon 	uint32_t period_us = TU_TO_USEC(period); /* convert to us unit */
425*572ff6f6SMatthew Dillon 	uint32_t nextStart_us = TU_TO_USEC(nextStart); /* convert to us unit */
426*572ff6f6SMatthew Dillon 	if (flag & HAL_QUIET_ENABLE) {
427*572ff6f6SMatthew Dillon 		if ((!nextStart) || (flag & HAL_QUIET_ADD_CURRENT_TSF)) {
428*572ff6f6SMatthew Dillon 			/* Add the nextStart offset to the current TSF */
429*572ff6f6SMatthew Dillon 			nextStart_us += OS_REG_READ(ah, AR_TSF_L32);
430*572ff6f6SMatthew Dillon 		}
431*572ff6f6SMatthew Dillon 		if (flag & HAL_QUIET_ADD_SWBA_RESP_TIME) {
432*572ff6f6SMatthew Dillon 			nextStart_us += ah->ah_config.ah_sw_beacon_response_time;
433*572ff6f6SMatthew Dillon 		}
434*572ff6f6SMatthew Dillon 		OS_REG_RMW_FIELD(ah, AR_QUIET1, AR_QUIET1_QUIET_ACK_CTS_ENABLE, 1);
435*572ff6f6SMatthew Dillon 		OS_REG_WRITE(ah, AR_QUIET2, SM(duration, AR_QUIET2_QUIET_DUR));
436*572ff6f6SMatthew Dillon 		OS_REG_WRITE(ah, AR_QUIET_PERIOD, period_us);
437*572ff6f6SMatthew Dillon 		OS_REG_WRITE(ah, AR_NEXT_QUIET, nextStart_us);
438*572ff6f6SMatthew Dillon 		OS_REG_SET_BIT(ah, AR_TIMER_MODE, AR_TIMER_MODE_QUIET);
439*572ff6f6SMatthew Dillon 	} else {
440*572ff6f6SMatthew Dillon 		OS_REG_CLR_BIT(ah, AR_TIMER_MODE, AR_TIMER_MODE_QUIET);
441*572ff6f6SMatthew Dillon 	}
442*572ff6f6SMatthew Dillon 	return HAL_OK;
443*572ff6f6SMatthew Dillon }
444*572ff6f6SMatthew Dillon #undef	TU_TO_USEC
445*572ff6f6SMatthew Dillon 
446*572ff6f6SMatthew Dillon HAL_STATUS
ar5416GetCapability(struct ath_hal * ah,HAL_CAPABILITY_TYPE type,uint32_t capability,uint32_t * result)447*572ff6f6SMatthew Dillon ar5416GetCapability(struct ath_hal *ah, HAL_CAPABILITY_TYPE type,
448*572ff6f6SMatthew Dillon         uint32_t capability, uint32_t *result)
449*572ff6f6SMatthew Dillon {
450*572ff6f6SMatthew Dillon 	switch (type) {
451*572ff6f6SMatthew Dillon 	case HAL_CAP_BB_HANG:
452*572ff6f6SMatthew Dillon 		switch (capability) {
453*572ff6f6SMatthew Dillon 		case HAL_BB_HANG_RIFS:
454*572ff6f6SMatthew Dillon 			return (AR_SREV_HOWL(ah) || AR_SREV_SOWL(ah)) ? HAL_OK : HAL_ENOTSUPP;
455*572ff6f6SMatthew Dillon 		case HAL_BB_HANG_DFS:
456*572ff6f6SMatthew Dillon 			return (AR_SREV_HOWL(ah) || AR_SREV_SOWL(ah)) ? HAL_OK : HAL_ENOTSUPP;
457*572ff6f6SMatthew Dillon 		case HAL_BB_HANG_RX_CLEAR:
458*572ff6f6SMatthew Dillon 			return AR_SREV_MERLIN(ah) ? HAL_OK : HAL_ENOTSUPP;
459*572ff6f6SMatthew Dillon 		}
460*572ff6f6SMatthew Dillon 		break;
461*572ff6f6SMatthew Dillon 	case HAL_CAP_MAC_HANG:
462*572ff6f6SMatthew Dillon 		return ((ah->ah_macVersion == AR_XSREV_VERSION_OWL_PCI) ||
463*572ff6f6SMatthew Dillon 		    (ah->ah_macVersion == AR_XSREV_VERSION_OWL_PCIE) ||
464*572ff6f6SMatthew Dillon 		    AR_SREV_HOWL(ah) || AR_SREV_SOWL(ah)) ?
465*572ff6f6SMatthew Dillon 			HAL_OK : HAL_ENOTSUPP;
466*572ff6f6SMatthew Dillon 	case HAL_CAP_DIVERSITY:		/* disable classic fast diversity */
467*572ff6f6SMatthew Dillon 		return HAL_ENXIO;
468*572ff6f6SMatthew Dillon 	case HAL_CAP_ENFORCE_TXOP:
469*572ff6f6SMatthew Dillon 		if (capability == 0)
470*572ff6f6SMatthew Dillon 			return (HAL_OK);
471*572ff6f6SMatthew Dillon 		if (capability != 1)
472*572ff6f6SMatthew Dillon 			return (HAL_ENOTSUPP);
473*572ff6f6SMatthew Dillon 		(*result) =
474*572ff6f6SMatthew Dillon 		    !! (AH5212(ah)->ah_miscMode & AR_PCU_TXOP_TBTT_LIMIT_ENA);
475*572ff6f6SMatthew Dillon 		return (HAL_OK);
476*572ff6f6SMatthew Dillon 	default:
477*572ff6f6SMatthew Dillon 		break;
478*572ff6f6SMatthew Dillon 	}
479*572ff6f6SMatthew Dillon 	return ar5212GetCapability(ah, type, capability, result);
480*572ff6f6SMatthew Dillon }
481*572ff6f6SMatthew Dillon 
482*572ff6f6SMatthew Dillon HAL_BOOL
ar5416SetCapability(struct ath_hal * ah,HAL_CAPABILITY_TYPE type,u_int32_t capability,u_int32_t setting,HAL_STATUS * status)483*572ff6f6SMatthew Dillon ar5416SetCapability(struct ath_hal *ah, HAL_CAPABILITY_TYPE type,
484*572ff6f6SMatthew Dillon     u_int32_t capability, u_int32_t setting, HAL_STATUS *status)
485*572ff6f6SMatthew Dillon {
486*572ff6f6SMatthew Dillon 	HAL_CAPABILITIES *pCap = &AH_PRIVATE(ah)->ah_caps;
487*572ff6f6SMatthew Dillon 
488*572ff6f6SMatthew Dillon 	switch (type) {
489*572ff6f6SMatthew Dillon 	case HAL_CAP_RX_CHAINMASK:
490*572ff6f6SMatthew Dillon 		setting &= ath_hal_eepromGet(ah, AR_EEP_RXMASK, NULL);
491*572ff6f6SMatthew Dillon 		pCap->halRxChainMask = setting;
492*572ff6f6SMatthew Dillon 		if (owl_get_ntxchains(setting) > 2)
493*572ff6f6SMatthew Dillon 			pCap->halRxStreams = 2;
494*572ff6f6SMatthew Dillon 		else
495*572ff6f6SMatthew Dillon 			pCap->halRxStreams = 1;
496*572ff6f6SMatthew Dillon 		return AH_TRUE;
497*572ff6f6SMatthew Dillon 	case HAL_CAP_TX_CHAINMASK:
498*572ff6f6SMatthew Dillon 		setting &= ath_hal_eepromGet(ah, AR_EEP_TXMASK, NULL);
499*572ff6f6SMatthew Dillon 		pCap->halTxChainMask = setting;
500*572ff6f6SMatthew Dillon 		if (owl_get_ntxchains(setting) > 2)
501*572ff6f6SMatthew Dillon 			pCap->halTxStreams = 2;
502*572ff6f6SMatthew Dillon 		else
503*572ff6f6SMatthew Dillon 			pCap->halTxStreams = 1;
504*572ff6f6SMatthew Dillon 		return AH_TRUE;
505*572ff6f6SMatthew Dillon 	case HAL_CAP_ENFORCE_TXOP:
506*572ff6f6SMatthew Dillon 		if (capability != 1)
507*572ff6f6SMatthew Dillon 			return AH_FALSE;
508*572ff6f6SMatthew Dillon 		if (setting) {
509*572ff6f6SMatthew Dillon 			AH5212(ah)->ah_miscMode
510*572ff6f6SMatthew Dillon 			    |= AR_PCU_TXOP_TBTT_LIMIT_ENA;
511*572ff6f6SMatthew Dillon 			OS_REG_SET_BIT(ah, AR_MISC_MODE,
512*572ff6f6SMatthew Dillon 			    AR_PCU_TXOP_TBTT_LIMIT_ENA);
513*572ff6f6SMatthew Dillon 		} else {
514*572ff6f6SMatthew Dillon 			AH5212(ah)->ah_miscMode
515*572ff6f6SMatthew Dillon 			    &= ~AR_PCU_TXOP_TBTT_LIMIT_ENA;
516*572ff6f6SMatthew Dillon 			OS_REG_CLR_BIT(ah, AR_MISC_MODE,
517*572ff6f6SMatthew Dillon 			    AR_PCU_TXOP_TBTT_LIMIT_ENA);
518*572ff6f6SMatthew Dillon 		}
519*572ff6f6SMatthew Dillon 		return AH_TRUE;
520*572ff6f6SMatthew Dillon 	default:
521*572ff6f6SMatthew Dillon 		break;
522*572ff6f6SMatthew Dillon 	}
523*572ff6f6SMatthew Dillon 	return ar5212SetCapability(ah, type, capability, setting, status);
524*572ff6f6SMatthew Dillon }
525*572ff6f6SMatthew Dillon 
526*572ff6f6SMatthew Dillon static int ar5416DetectMacHang(struct ath_hal *ah);
527*572ff6f6SMatthew Dillon static int ar5416DetectBBHang(struct ath_hal *ah);
528*572ff6f6SMatthew Dillon 
529*572ff6f6SMatthew Dillon HAL_BOOL
ar5416GetDiagState(struct ath_hal * ah,int request,const void * args,uint32_t argsize,void ** result,uint32_t * resultsize)530*572ff6f6SMatthew Dillon ar5416GetDiagState(struct ath_hal *ah, int request,
531*572ff6f6SMatthew Dillon 	const void *args, uint32_t argsize,
532*572ff6f6SMatthew Dillon 	void **result, uint32_t *resultsize)
533*572ff6f6SMatthew Dillon {
534*572ff6f6SMatthew Dillon 	struct ath_hal_5416 *ahp = AH5416(ah);
535*572ff6f6SMatthew Dillon 	int hangs;
536*572ff6f6SMatthew Dillon 
537*572ff6f6SMatthew Dillon 	if (ath_hal_getdiagstate(ah, request, args, argsize, result, resultsize))
538*572ff6f6SMatthew Dillon 		return AH_TRUE;
539*572ff6f6SMatthew Dillon 	switch (request) {
540*572ff6f6SMatthew Dillon 	case HAL_DIAG_EEPROM:
541*572ff6f6SMatthew Dillon 		return ath_hal_eepromDiag(ah, request,
542*572ff6f6SMatthew Dillon 		    args, argsize, result, resultsize);
543*572ff6f6SMatthew Dillon 	case HAL_DIAG_CHECK_HANGS:
544*572ff6f6SMatthew Dillon 		if (argsize != sizeof(int))
545*572ff6f6SMatthew Dillon 			return AH_FALSE;
546*572ff6f6SMatthew Dillon 		hangs = *(const int *) args;
547*572ff6f6SMatthew Dillon 		ahp->ah_hangs = 0;
548*572ff6f6SMatthew Dillon 		if (hangs & HAL_BB_HANGS)
549*572ff6f6SMatthew Dillon 			ahp->ah_hangs |= ar5416DetectBBHang(ah);
550*572ff6f6SMatthew Dillon 		/* NB: if BB is hung MAC will be hung too so skip check */
551*572ff6f6SMatthew Dillon 		if (ahp->ah_hangs == 0 && (hangs & HAL_MAC_HANGS))
552*572ff6f6SMatthew Dillon 			ahp->ah_hangs |= ar5416DetectMacHang(ah);
553*572ff6f6SMatthew Dillon 		*result = &ahp->ah_hangs;
554*572ff6f6SMatthew Dillon 		*resultsize = sizeof(ahp->ah_hangs);
555*572ff6f6SMatthew Dillon 		return AH_TRUE;
556*572ff6f6SMatthew Dillon 	}
557*572ff6f6SMatthew Dillon 	return ar5212GetDiagState(ah, request,
558*572ff6f6SMatthew Dillon 	    args, argsize, result, resultsize);
559*572ff6f6SMatthew Dillon }
560*572ff6f6SMatthew Dillon 
561*572ff6f6SMatthew Dillon HAL_BOOL
ar5416SetRifsDelay(struct ath_hal * ah,const struct ieee80211_channel * chan,HAL_BOOL enable)562*572ff6f6SMatthew Dillon ar5416SetRifsDelay(struct ath_hal *ah, const struct ieee80211_channel *chan,
563*572ff6f6SMatthew Dillon     HAL_BOOL enable)
564*572ff6f6SMatthew Dillon {
565*572ff6f6SMatthew Dillon 	uint32_t val;
566*572ff6f6SMatthew Dillon 	HAL_BOOL is_chan_2g = AH_FALSE;
567*572ff6f6SMatthew Dillon 	HAL_BOOL is_ht40 = AH_FALSE;
568*572ff6f6SMatthew Dillon 
569*572ff6f6SMatthew Dillon 	if (chan)
570*572ff6f6SMatthew Dillon 		is_chan_2g = IEEE80211_IS_CHAN_2GHZ(chan);
571*572ff6f6SMatthew Dillon 
572*572ff6f6SMatthew Dillon 	if (chan)
573*572ff6f6SMatthew Dillon 		is_ht40 = IEEE80211_IS_CHAN_HT40(chan);
574*572ff6f6SMatthew Dillon 
575*572ff6f6SMatthew Dillon 	/* Only support disabling RIFS delay for now */
576*572ff6f6SMatthew Dillon 	HALASSERT(enable == AH_FALSE);
577*572ff6f6SMatthew Dillon 
578*572ff6f6SMatthew Dillon 	if (enable == AH_TRUE)
579*572ff6f6SMatthew Dillon 		return AH_FALSE;
580*572ff6f6SMatthew Dillon 
581*572ff6f6SMatthew Dillon 	/* Change RIFS init delay to 0 */
582*572ff6f6SMatthew Dillon 	val = OS_REG_READ(ah, AR_PHY_HEAVY_CLIP_FACTOR_RIFS);
583*572ff6f6SMatthew Dillon 	val &= ~AR_PHY_RIFS_INIT_DELAY;
584*572ff6f6SMatthew Dillon 	OS_REG_WRITE(ah, AR_PHY_HEAVY_CLIP_FACTOR_RIFS, val);
585*572ff6f6SMatthew Dillon 
586*572ff6f6SMatthew Dillon 	/*
587*572ff6f6SMatthew Dillon 	 * For Owl, RIFS RX parameters are controlled differently;
588*572ff6f6SMatthew Dillon 	 * it isn't enabled in the inivals by default.
589*572ff6f6SMatthew Dillon 	 *
590*572ff6f6SMatthew Dillon 	 * For Sowl/Howl, RIFS RX is enabled in the inivals by default;
591*572ff6f6SMatthew Dillon 	 * the following code sets them back to non-RIFS values.
592*572ff6f6SMatthew Dillon 	 *
593*572ff6f6SMatthew Dillon 	 * For > Sowl/Howl, RIFS RX can be left on by default and so
594*572ff6f6SMatthew Dillon 	 * this function shouldn't be called.
595*572ff6f6SMatthew Dillon 	 */
596*572ff6f6SMatthew Dillon 	if ((! AR_SREV_SOWL(ah)) && (! AR_SREV_HOWL(ah)))
597*572ff6f6SMatthew Dillon 		return AH_TRUE;
598*572ff6f6SMatthew Dillon 
599*572ff6f6SMatthew Dillon 	/* Reset search delay to default values */
600*572ff6f6SMatthew Dillon 	if (is_chan_2g)
601*572ff6f6SMatthew Dillon 		if (is_ht40)
602*572ff6f6SMatthew Dillon 			OS_REG_WRITE(ah, AR_PHY_SEARCH_START_DELAY, 0x268);
603*572ff6f6SMatthew Dillon 		else
604*572ff6f6SMatthew Dillon 			OS_REG_WRITE(ah, AR_PHY_SEARCH_START_DELAY, 0x134);
605*572ff6f6SMatthew Dillon 	else
606*572ff6f6SMatthew Dillon 		if (is_ht40)
607*572ff6f6SMatthew Dillon 			OS_REG_WRITE(ah, AR_PHY_SEARCH_START_DELAY, 0x370);
608*572ff6f6SMatthew Dillon 		else
609*572ff6f6SMatthew Dillon 			OS_REG_WRITE(ah, AR_PHY_SEARCH_START_DELAY, 0x1b8);
610*572ff6f6SMatthew Dillon 
611*572ff6f6SMatthew Dillon 	return AH_TRUE;
612*572ff6f6SMatthew Dillon }
613*572ff6f6SMatthew Dillon 
614*572ff6f6SMatthew Dillon static HAL_BOOL
ar5416CompareDbgHang(struct ath_hal * ah,const mac_dbg_regs_t * regs,const hal_mac_hang_check_t * check)615*572ff6f6SMatthew Dillon ar5416CompareDbgHang(struct ath_hal *ah, const mac_dbg_regs_t *regs,
616*572ff6f6SMatthew Dillon     const hal_mac_hang_check_t *check)
617*572ff6f6SMatthew Dillon {
618*572ff6f6SMatthew Dillon 	int found_states;
619*572ff6f6SMatthew Dillon 
620*572ff6f6SMatthew Dillon 	found_states = 0;
621*572ff6f6SMatthew Dillon 	if (check->states & dcu_chain_state) {
622*572ff6f6SMatthew Dillon 		int i;
623*572ff6f6SMatthew Dillon 
624*572ff6f6SMatthew Dillon 		for (i = 0; i < 6; i++) {
625*572ff6f6SMatthew Dillon 			if (((regs->dma_dbg_4 >> (5*i)) & 0x1f) ==
626*572ff6f6SMatthew Dillon 			    check->dcu_chain_state)
627*572ff6f6SMatthew Dillon 				found_states |= dcu_chain_state;
628*572ff6f6SMatthew Dillon 		}
629*572ff6f6SMatthew Dillon 		for (i = 0; i < 4; i++) {
630*572ff6f6SMatthew Dillon 			if (((regs->dma_dbg_5 >> (5*i)) & 0x1f) ==
631*572ff6f6SMatthew Dillon 			    check->dcu_chain_state)
632*572ff6f6SMatthew Dillon 				found_states |= dcu_chain_state;
633*572ff6f6SMatthew Dillon 		}
634*572ff6f6SMatthew Dillon 	}
635*572ff6f6SMatthew Dillon 	if (check->states & dcu_complete_state) {
636*572ff6f6SMatthew Dillon 		if ((regs->dma_dbg_6 & 0x3) == check->dcu_complete_state)
637*572ff6f6SMatthew Dillon 			found_states |= dcu_complete_state;
638*572ff6f6SMatthew Dillon 	}
639*572ff6f6SMatthew Dillon 	if (check->states & qcu_stitch_state) {
640*572ff6f6SMatthew Dillon 		if (((regs->dma_dbg_3 >> 18) & 0xf) == check->qcu_stitch_state)
641*572ff6f6SMatthew Dillon 			found_states |= qcu_stitch_state;
642*572ff6f6SMatthew Dillon 	}
643*572ff6f6SMatthew Dillon 	if (check->states & qcu_fetch_state) {
644*572ff6f6SMatthew Dillon 		if (((regs->dma_dbg_3 >> 22) & 0xf) == check->qcu_fetch_state)
645*572ff6f6SMatthew Dillon 			found_states |= qcu_fetch_state;
646*572ff6f6SMatthew Dillon 	}
647*572ff6f6SMatthew Dillon 	if (check->states & qcu_complete_state) {
648*572ff6f6SMatthew Dillon 		if (((regs->dma_dbg_3 >> 26) & 0x7) == check->qcu_complete_state)
649*572ff6f6SMatthew Dillon 			found_states |= qcu_complete_state;
650*572ff6f6SMatthew Dillon 	}
651*572ff6f6SMatthew Dillon 	return (found_states == check->states);
652*572ff6f6SMatthew Dillon }
653*572ff6f6SMatthew Dillon 
654*572ff6f6SMatthew Dillon #define NUM_STATUS_READS 50
655*572ff6f6SMatthew Dillon 
656*572ff6f6SMatthew Dillon static int
ar5416DetectMacHang(struct ath_hal * ah)657*572ff6f6SMatthew Dillon ar5416DetectMacHang(struct ath_hal *ah)
658*572ff6f6SMatthew Dillon {
659*572ff6f6SMatthew Dillon 	static const hal_mac_hang_check_t hang_sig1 = {
660*572ff6f6SMatthew Dillon 		.dcu_chain_state	= 0x6,
661*572ff6f6SMatthew Dillon 		.dcu_complete_state	= 0x1,
662*572ff6f6SMatthew Dillon 		.states			= dcu_chain_state
663*572ff6f6SMatthew Dillon 					| dcu_complete_state,
664*572ff6f6SMatthew Dillon 	};
665*572ff6f6SMatthew Dillon 	static const hal_mac_hang_check_t hang_sig2 = {
666*572ff6f6SMatthew Dillon 		.qcu_stitch_state	= 0x9,
667*572ff6f6SMatthew Dillon 		.qcu_fetch_state	= 0x8,
668*572ff6f6SMatthew Dillon 		.qcu_complete_state	= 0x4,
669*572ff6f6SMatthew Dillon 		.states			= qcu_stitch_state
670*572ff6f6SMatthew Dillon 					| qcu_fetch_state
671*572ff6f6SMatthew Dillon 					| qcu_complete_state,
672*572ff6f6SMatthew Dillon         };
673*572ff6f6SMatthew Dillon 	mac_dbg_regs_t mac_dbg;
674*572ff6f6SMatthew Dillon 	int i;
675*572ff6f6SMatthew Dillon 
676*572ff6f6SMatthew Dillon 	mac_dbg.dma_dbg_3 = OS_REG_READ(ah, AR_DMADBG_3);
677*572ff6f6SMatthew Dillon 	mac_dbg.dma_dbg_4 = OS_REG_READ(ah, AR_DMADBG_4);
678*572ff6f6SMatthew Dillon 	mac_dbg.dma_dbg_5 = OS_REG_READ(ah, AR_DMADBG_5);
679*572ff6f6SMatthew Dillon 	mac_dbg.dma_dbg_6 = OS_REG_READ(ah, AR_DMADBG_6);
680*572ff6f6SMatthew Dillon 	for (i = 1; i <= NUM_STATUS_READS; i++) {
681*572ff6f6SMatthew Dillon 		if (mac_dbg.dma_dbg_3 != OS_REG_READ(ah, AR_DMADBG_3) ||
682*572ff6f6SMatthew Dillon 		    mac_dbg.dma_dbg_4 != OS_REG_READ(ah, AR_DMADBG_4) ||
683*572ff6f6SMatthew Dillon 		    mac_dbg.dma_dbg_5 != OS_REG_READ(ah, AR_DMADBG_5) ||
684*572ff6f6SMatthew Dillon 		    mac_dbg.dma_dbg_6 != OS_REG_READ(ah, AR_DMADBG_6))
685*572ff6f6SMatthew Dillon 			return 0;
686*572ff6f6SMatthew Dillon 	}
687*572ff6f6SMatthew Dillon 
688*572ff6f6SMatthew Dillon 	if (ar5416CompareDbgHang(ah, &mac_dbg, &hang_sig1))
689*572ff6f6SMatthew Dillon 		return HAL_MAC_HANG_SIG1;
690*572ff6f6SMatthew Dillon 	if (ar5416CompareDbgHang(ah, &mac_dbg, &hang_sig2))
691*572ff6f6SMatthew Dillon 		return HAL_MAC_HANG_SIG2;
692*572ff6f6SMatthew Dillon 
693*572ff6f6SMatthew Dillon 	HALDEBUG(ah, HAL_DEBUG_HANG, "%s Found an unknown MAC hang signature "
694*572ff6f6SMatthew Dillon 	    "DMADBG_3=0x%x DMADBG_4=0x%x DMADBG_5=0x%x DMADBG_6=0x%x\n",
695*572ff6f6SMatthew Dillon 	    __func__, mac_dbg.dma_dbg_3, mac_dbg.dma_dbg_4, mac_dbg.dma_dbg_5,
696*572ff6f6SMatthew Dillon 	    mac_dbg.dma_dbg_6);
697*572ff6f6SMatthew Dillon 
698*572ff6f6SMatthew Dillon 	return 0;
699*572ff6f6SMatthew Dillon }
700*572ff6f6SMatthew Dillon 
701*572ff6f6SMatthew Dillon /*
702*572ff6f6SMatthew Dillon  * Determine if the baseband using the Observation Bus Register
703*572ff6f6SMatthew Dillon  */
704*572ff6f6SMatthew Dillon static int
ar5416DetectBBHang(struct ath_hal * ah)705*572ff6f6SMatthew Dillon ar5416DetectBBHang(struct ath_hal *ah)
706*572ff6f6SMatthew Dillon {
707*572ff6f6SMatthew Dillon #define N(a) (sizeof(a)/sizeof(a[0]))
708*572ff6f6SMatthew Dillon 	/*
709*572ff6f6SMatthew Dillon 	 * Check the PCU Observation Bus 1 register (0x806c)
710*572ff6f6SMatthew Dillon 	 * NUM_STATUS_READS times
711*572ff6f6SMatthew Dillon 	 *
712*572ff6f6SMatthew Dillon 	 * 4 known BB hang signatures -
713*572ff6f6SMatthew Dillon 	 * [1] bits 8,9,11 are 0. State machine state (bits 25-31) is 0x1E
714*572ff6f6SMatthew Dillon 	 * [2] bits 8,9 are 1, bit 11 is 0. State machine state
715*572ff6f6SMatthew Dillon 	 *     (bits 25-31) is 0x52
716*572ff6f6SMatthew Dillon 	 * [3] bits 8,9 are 1, bit 11 is 0. State machine state
717*572ff6f6SMatthew Dillon 	 *     (bits 25-31) is 0x18
718*572ff6f6SMatthew Dillon 	 * [4] bit 10 is 1, bit 11 is 0. WEP state (bits 12-17) is 0x2,
719*572ff6f6SMatthew Dillon 	 *     Rx State (bits 20-24) is 0x7.
720*572ff6f6SMatthew Dillon 	 */
721*572ff6f6SMatthew Dillon 	static const struct {
722*572ff6f6SMatthew Dillon 		uint32_t val;
723*572ff6f6SMatthew Dillon 		uint32_t mask;
724*572ff6f6SMatthew Dillon 		int code;
725*572ff6f6SMatthew Dillon 	} hang_list[] = {
726*572ff6f6SMatthew Dillon 		/* Reg Value   Reg Mask    Hang Code XXX */
727*572ff6f6SMatthew Dillon 		{ 0x1E000000, 0x7E000B00, HAL_BB_HANG_DFS },
728*572ff6f6SMatthew Dillon 		{ 0x52000B00, 0x7E000B00, HAL_BB_HANG_RIFS },
729*572ff6f6SMatthew Dillon 		{ 0x18000B00, 0x7E000B00, HAL_BB_HANG_RX_CLEAR },
730*572ff6f6SMatthew Dillon 		{ 0x00702400, 0x7E7FFFEF, HAL_BB_HANG_RX_CLEAR }
731*572ff6f6SMatthew Dillon 	};
732*572ff6f6SMatthew Dillon 	uint32_t hang_sig;
733*572ff6f6SMatthew Dillon 	int i;
734*572ff6f6SMatthew Dillon 
735*572ff6f6SMatthew Dillon 	hang_sig = OS_REG_READ(ah, AR_OBSERV_1);
736*572ff6f6SMatthew Dillon 	for (i = 1; i <= NUM_STATUS_READS; i++) {
737*572ff6f6SMatthew Dillon 		if (hang_sig != OS_REG_READ(ah, AR_OBSERV_1))
738*572ff6f6SMatthew Dillon 			return 0;
739*572ff6f6SMatthew Dillon 	}
740*572ff6f6SMatthew Dillon 	for (i = 0; i < N(hang_list); i++)
741*572ff6f6SMatthew Dillon 		if ((hang_sig & hang_list[i].mask) == hang_list[i].val) {
742*572ff6f6SMatthew Dillon 			HALDEBUG(ah, HAL_DEBUG_HANG,
743*572ff6f6SMatthew Dillon 			    "%s BB hang, signature 0x%x, code 0x%x\n",
744*572ff6f6SMatthew Dillon 			    __func__, hang_sig, hang_list[i].code);
745*572ff6f6SMatthew Dillon 			return hang_list[i].code;
746*572ff6f6SMatthew Dillon 		}
747*572ff6f6SMatthew Dillon 
748*572ff6f6SMatthew Dillon 	HALDEBUG(ah, HAL_DEBUG_HANG, "%s Found an unknown BB hang signature! "
749*572ff6f6SMatthew Dillon 	    "<0x806c>=0x%x\n", __func__, hang_sig);
750*572ff6f6SMatthew Dillon 
751*572ff6f6SMatthew Dillon 	return 0;
752*572ff6f6SMatthew Dillon #undef N
753*572ff6f6SMatthew Dillon }
754*572ff6f6SMatthew Dillon #undef NUM_STATUS_READS
755