1572ff6f6SMatthew Dillon /*
2572ff6f6SMatthew Dillon  * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
3572ff6f6SMatthew Dillon  * Copyright (c) 2002-2008 Atheros Communications, Inc.
4572ff6f6SMatthew Dillon  *
5572ff6f6SMatthew Dillon  * Permission to use, copy, modify, and/or distribute this software for any
6572ff6f6SMatthew Dillon  * purpose with or without fee is hereby granted, provided that the above
7572ff6f6SMatthew Dillon  * copyright notice and this permission notice appear in all copies.
8572ff6f6SMatthew Dillon  *
9572ff6f6SMatthew Dillon  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10572ff6f6SMatthew Dillon  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11572ff6f6SMatthew Dillon  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12572ff6f6SMatthew Dillon  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13572ff6f6SMatthew Dillon  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14572ff6f6SMatthew Dillon  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15572ff6f6SMatthew Dillon  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16572ff6f6SMatthew Dillon  *
17572ff6f6SMatthew Dillon  * $FreeBSD$
18572ff6f6SMatthew Dillon  */
19572ff6f6SMatthew Dillon #include "opt_ah.h"
20572ff6f6SMatthew Dillon 
21572ff6f6SMatthew Dillon #include "ah.h"
22572ff6f6SMatthew Dillon #include "ah_internal.h"
23572ff6f6SMatthew Dillon 
24572ff6f6SMatthew Dillon #include "ar5416/ar5416.h"
25572ff6f6SMatthew Dillon #include "ar5416/ar5416reg.h"
26572ff6f6SMatthew Dillon 
27572ff6f6SMatthew Dillon /*
28572ff6f6SMatthew Dillon  * Checks to see if an interrupt is pending on our NIC
29572ff6f6SMatthew Dillon  *
30572ff6f6SMatthew Dillon  * Returns: TRUE    if an interrupt is pending
31572ff6f6SMatthew Dillon  *          FALSE   if not
32572ff6f6SMatthew Dillon  */
33572ff6f6SMatthew Dillon HAL_BOOL
ar5416IsInterruptPending(struct ath_hal * ah)34572ff6f6SMatthew Dillon ar5416IsInterruptPending(struct ath_hal *ah)
35572ff6f6SMatthew Dillon {
36572ff6f6SMatthew Dillon 	uint32_t isr;
37572ff6f6SMatthew Dillon 
38572ff6f6SMatthew Dillon 	if (AR_SREV_HOWL(ah))
39572ff6f6SMatthew Dillon 		return AH_TRUE;
40572ff6f6SMatthew Dillon 
41572ff6f6SMatthew Dillon 	/*
42572ff6f6SMatthew Dillon 	 * Some platforms trigger our ISR before applying power to
43572ff6f6SMatthew Dillon 	 * the card, so make sure the INTPEND is really 1, not 0xffffffff.
44572ff6f6SMatthew Dillon 	 */
45572ff6f6SMatthew Dillon 	isr = OS_REG_READ(ah, AR_INTR_ASYNC_CAUSE);
46572ff6f6SMatthew Dillon 	if (isr != AR_INTR_SPURIOUS && (isr & AR_INTR_MAC_IRQ) != 0)
47572ff6f6SMatthew Dillon 		return AH_TRUE;
48572ff6f6SMatthew Dillon 
49572ff6f6SMatthew Dillon 	isr = OS_REG_READ(ah, AR_INTR_SYNC_CAUSE);
50572ff6f6SMatthew Dillon 	if (isr != AR_INTR_SPURIOUS && (isr & AR_INTR_SYNC_DEFAULT))
51572ff6f6SMatthew Dillon 		return AH_TRUE;
52572ff6f6SMatthew Dillon 
53572ff6f6SMatthew Dillon 	return AH_FALSE;
54572ff6f6SMatthew Dillon }
55572ff6f6SMatthew Dillon 
56572ff6f6SMatthew Dillon /*
57572ff6f6SMatthew Dillon  * Reads the Interrupt Status Register value from the NIC, thus deasserting
58572ff6f6SMatthew Dillon  * the interrupt line, and returns both the masked and unmasked mapped ISR
59572ff6f6SMatthew Dillon  * values.  The value returned is mapped to abstract the hw-specific bit
60572ff6f6SMatthew Dillon  * locations in the Interrupt Status Register.
61572ff6f6SMatthew Dillon  *
62572ff6f6SMatthew Dillon  * (*masked) is cleared on initial call.
63572ff6f6SMatthew Dillon  *
64572ff6f6SMatthew Dillon  * Returns: A hardware-abstracted bitmap of all non-masked-out
65572ff6f6SMatthew Dillon  *          interrupts pending, as well as an unmasked value
66572ff6f6SMatthew Dillon  */
67572ff6f6SMatthew Dillon HAL_BOOL
ar5416GetPendingInterrupts(struct ath_hal * ah,HAL_INT * masked)68572ff6f6SMatthew Dillon ar5416GetPendingInterrupts(struct ath_hal *ah, HAL_INT *masked)
69572ff6f6SMatthew Dillon {
70572ff6f6SMatthew Dillon 	uint32_t isr, isr0, isr1, sync_cause = 0, o_sync_cause = 0;
71572ff6f6SMatthew Dillon 	HAL_CAPABILITIES *pCap = &AH_PRIVATE(ah)->ah_caps;
72572ff6f6SMatthew Dillon 
73572ff6f6SMatthew Dillon #ifdef	AH_INTERRUPT_DEBUGGING
74572ff6f6SMatthew Dillon 	/*
75572ff6f6SMatthew Dillon 	 * Blank the interrupt debugging area regardless.
76572ff6f6SMatthew Dillon 	 */
77572ff6f6SMatthew Dillon 	bzero(&ah->ah_intrstate, sizeof(ah->ah_intrstate));
78572ff6f6SMatthew Dillon 	ah->ah_syncstate = 0;
79572ff6f6SMatthew Dillon #endif
80572ff6f6SMatthew Dillon 
81572ff6f6SMatthew Dillon 	/*
82572ff6f6SMatthew Dillon 	 * Verify there's a mac interrupt and the RTC is on.
83572ff6f6SMatthew Dillon 	 */
84572ff6f6SMatthew Dillon 	if (AR_SREV_HOWL(ah)) {
85572ff6f6SMatthew Dillon 		*masked = 0;
86572ff6f6SMatthew Dillon 		isr = OS_REG_READ(ah, AR_ISR);
87572ff6f6SMatthew Dillon 	} else {
88572ff6f6SMatthew Dillon 		if ((OS_REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) &&
89572ff6f6SMatthew Dillon 		    (OS_REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M) == AR_RTC_STATUS_ON)
90572ff6f6SMatthew Dillon 			isr = OS_REG_READ(ah, AR_ISR);
91572ff6f6SMatthew Dillon 		else
92572ff6f6SMatthew Dillon 			isr = 0;
93572ff6f6SMatthew Dillon #ifdef	AH_INTERRUPT_DEBUGGING
94572ff6f6SMatthew Dillon 		ah->ah_syncstate =
95572ff6f6SMatthew Dillon #endif
96572ff6f6SMatthew Dillon 		o_sync_cause = sync_cause = OS_REG_READ(ah, AR_INTR_SYNC_CAUSE);
97572ff6f6SMatthew Dillon 		sync_cause &= AR_INTR_SYNC_DEFAULT;
98572ff6f6SMatthew Dillon 		*masked = 0;
99572ff6f6SMatthew Dillon 
100572ff6f6SMatthew Dillon 		if (isr == 0 && sync_cause == 0)
101572ff6f6SMatthew Dillon 			return AH_FALSE;
102572ff6f6SMatthew Dillon 	}
103572ff6f6SMatthew Dillon 
104572ff6f6SMatthew Dillon #ifdef	AH_INTERRUPT_DEBUGGING
105572ff6f6SMatthew Dillon 	ah->ah_intrstate[0] = isr;
106572ff6f6SMatthew Dillon 	ah->ah_intrstate[1] = OS_REG_READ(ah, AR_ISR_S0);
107572ff6f6SMatthew Dillon 	ah->ah_intrstate[2] = OS_REG_READ(ah, AR_ISR_S1);
108572ff6f6SMatthew Dillon 	ah->ah_intrstate[3] = OS_REG_READ(ah, AR_ISR_S2);
109572ff6f6SMatthew Dillon 	ah->ah_intrstate[4] = OS_REG_READ(ah, AR_ISR_S3);
110572ff6f6SMatthew Dillon 	ah->ah_intrstate[5] = OS_REG_READ(ah, AR_ISR_S4);
111572ff6f6SMatthew Dillon 	ah->ah_intrstate[6] = OS_REG_READ(ah, AR_ISR_S5);
112572ff6f6SMatthew Dillon #endif
113572ff6f6SMatthew Dillon 
114572ff6f6SMatthew Dillon 	if (isr != 0) {
115572ff6f6SMatthew Dillon 		struct ath_hal_5212 *ahp = AH5212(ah);
116572ff6f6SMatthew Dillon 		uint32_t mask2;
117572ff6f6SMatthew Dillon 
118572ff6f6SMatthew Dillon 		mask2 = 0;
119572ff6f6SMatthew Dillon 		if (isr & AR_ISR_BCNMISC) {
120572ff6f6SMatthew Dillon 			uint32_t isr2 = OS_REG_READ(ah, AR_ISR_S2);
121572ff6f6SMatthew Dillon 			if (isr2 & AR_ISR_S2_TIM)
122572ff6f6SMatthew Dillon 				mask2 |= HAL_INT_TIM;
123572ff6f6SMatthew Dillon 			if (isr2 & AR_ISR_S2_DTIM)
124572ff6f6SMatthew Dillon 				mask2 |= HAL_INT_DTIM;
125572ff6f6SMatthew Dillon 			if (isr2 & AR_ISR_S2_DTIMSYNC)
126572ff6f6SMatthew Dillon 				mask2 |= HAL_INT_DTIMSYNC;
127572ff6f6SMatthew Dillon 			if (isr2 & (AR_ISR_S2_CABEND ))
128572ff6f6SMatthew Dillon 				mask2 |= HAL_INT_CABEND;
129572ff6f6SMatthew Dillon 			if (isr2 & AR_ISR_S2_GTT)
130572ff6f6SMatthew Dillon 				mask2 |= HAL_INT_GTT;
131572ff6f6SMatthew Dillon 			if (isr2 & AR_ISR_S2_CST)
132572ff6f6SMatthew Dillon 				mask2 |= HAL_INT_CST;
133572ff6f6SMatthew Dillon 			if (isr2 & AR_ISR_S2_TSFOOR)
134572ff6f6SMatthew Dillon 				mask2 |= HAL_INT_TSFOOR;
135572ff6f6SMatthew Dillon 
136572ff6f6SMatthew Dillon 			/*
137572ff6f6SMatthew Dillon 			 * Don't mask out AR_BCNMISC; instead mask
138572ff6f6SMatthew Dillon 			 * out what causes it.
139572ff6f6SMatthew Dillon 			 */
140572ff6f6SMatthew Dillon 			OS_REG_WRITE(ah, AR_ISR_S2, isr2);
141572ff6f6SMatthew Dillon 			isr &= ~AR_ISR_BCNMISC;
142572ff6f6SMatthew Dillon 		}
143572ff6f6SMatthew Dillon 
144572ff6f6SMatthew Dillon 		if (isr == 0xffffffff) {
145572ff6f6SMatthew Dillon 			*masked = 0;
146572ff6f6SMatthew Dillon 			return AH_FALSE;
147572ff6f6SMatthew Dillon 		}
148572ff6f6SMatthew Dillon 
149572ff6f6SMatthew Dillon 		*masked = isr & HAL_INT_COMMON;
150572ff6f6SMatthew Dillon 
151572ff6f6SMatthew Dillon 		if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
152572ff6f6SMatthew Dillon 			*masked |= HAL_INT_RX;
153572ff6f6SMatthew Dillon 		if (isr & (AR_ISR_TXMINTR | AR_ISR_TXINTM))
154572ff6f6SMatthew Dillon 			*masked |= HAL_INT_TX;
155572ff6f6SMatthew Dillon 
156572ff6f6SMatthew Dillon 		/*
157572ff6f6SMatthew Dillon 		 * When doing RX interrupt mitigation, the RXOK bit is set
158572ff6f6SMatthew Dillon 		 * in AR_ISR even if the relevant bit in AR_IMR is clear.
159572ff6f6SMatthew Dillon 		 * Since this interrupt may be due to another source, don't
160572ff6f6SMatthew Dillon 		 * just automatically set HAL_INT_RX if it's set, otherwise
161572ff6f6SMatthew Dillon 		 * we could prematurely service the RX queue.
162572ff6f6SMatthew Dillon 		 *
163572ff6f6SMatthew Dillon 		 * In some cases, the driver can even handle all the RX
164572ff6f6SMatthew Dillon 		 * frames just before the mitigation interrupt fires.
165572ff6f6SMatthew Dillon 		 * The subsequent RX processing trip will then end up
166572ff6f6SMatthew Dillon 		 * processing 0 frames.
167572ff6f6SMatthew Dillon 		 */
168572ff6f6SMatthew Dillon #ifdef	AH_AR5416_INTERRUPT_MITIGATION
169572ff6f6SMatthew Dillon 		if (isr & AR_ISR_RXERR)
170572ff6f6SMatthew Dillon 			*masked |= HAL_INT_RX;
171572ff6f6SMatthew Dillon #else
172572ff6f6SMatthew Dillon 		if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
173572ff6f6SMatthew Dillon 			*masked |= HAL_INT_RX;
174572ff6f6SMatthew Dillon #endif
175572ff6f6SMatthew Dillon 
176572ff6f6SMatthew Dillon 		if (isr & (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
177572ff6f6SMatthew Dillon 		    AR_ISR_TXEOL)) {
178572ff6f6SMatthew Dillon 			*masked |= HAL_INT_TX;
179572ff6f6SMatthew Dillon 
180572ff6f6SMatthew Dillon 			isr0 = OS_REG_READ(ah, AR_ISR_S0);
181572ff6f6SMatthew Dillon 			OS_REG_WRITE(ah, AR_ISR_S0, isr0);
182572ff6f6SMatthew Dillon 			isr1 = OS_REG_READ(ah, AR_ISR_S1);
183572ff6f6SMatthew Dillon 			OS_REG_WRITE(ah, AR_ISR_S1, isr1);
184572ff6f6SMatthew Dillon 
185572ff6f6SMatthew Dillon 			/*
186572ff6f6SMatthew Dillon 			 * Don't clear the primary ISR TX bits, clear
187572ff6f6SMatthew Dillon 			 * what causes them (S0/S1.)
188572ff6f6SMatthew Dillon 			 */
189572ff6f6SMatthew Dillon 			isr &= ~(AR_ISR_TXOK | AR_ISR_TXDESC |
190572ff6f6SMatthew Dillon 			    AR_ISR_TXERR | AR_ISR_TXEOL);
191572ff6f6SMatthew Dillon 
192572ff6f6SMatthew Dillon 			ahp->ah_intrTxqs |= MS(isr0, AR_ISR_S0_QCU_TXOK);
193572ff6f6SMatthew Dillon 			ahp->ah_intrTxqs |= MS(isr0, AR_ISR_S0_QCU_TXDESC);
194572ff6f6SMatthew Dillon 			ahp->ah_intrTxqs |= MS(isr1, AR_ISR_S1_QCU_TXERR);
195572ff6f6SMatthew Dillon 			ahp->ah_intrTxqs |= MS(isr1, AR_ISR_S1_QCU_TXEOL);
196572ff6f6SMatthew Dillon 		}
197572ff6f6SMatthew Dillon 
198572ff6f6SMatthew Dillon 		if ((isr & AR_ISR_GENTMR) || (! pCap->halAutoSleepSupport)) {
199572ff6f6SMatthew Dillon 			uint32_t isr5;
200572ff6f6SMatthew Dillon 			isr5 = OS_REG_READ(ah, AR_ISR_S5);
201572ff6f6SMatthew Dillon 			OS_REG_WRITE(ah, AR_ISR_S5, isr5);
202572ff6f6SMatthew Dillon 			isr &= ~AR_ISR_GENTMR;
203572ff6f6SMatthew Dillon 
204572ff6f6SMatthew Dillon 			if (! pCap->halAutoSleepSupport)
205572ff6f6SMatthew Dillon 				if (isr5 & AR_ISR_S5_TIM_TIMER)
206572ff6f6SMatthew Dillon 					*masked |= HAL_INT_TIM_TIMER;
207572ff6f6SMatthew Dillon 		}
208572ff6f6SMatthew Dillon 		*masked |= mask2;
209572ff6f6SMatthew Dillon 	}
210572ff6f6SMatthew Dillon 
211572ff6f6SMatthew Dillon 	/*
212572ff6f6SMatthew Dillon 	 * Since we're not using AR_ISR_RAC, clear the status bits
213572ff6f6SMatthew Dillon 	 * for handled interrupts here. For bits whose interrupt
214572ff6f6SMatthew Dillon 	 * source is a secondary register, those bits should've been
215572ff6f6SMatthew Dillon 	 * masked out - instead of those bits being written back,
216572ff6f6SMatthew Dillon 	 * their source (ie, the secondary status registers) should
217572ff6f6SMatthew Dillon 	 * be cleared. That way there are no race conditions with
218572ff6f6SMatthew Dillon 	 * new triggers coming in whilst they've been read/cleared.
219572ff6f6SMatthew Dillon 	 */
220572ff6f6SMatthew Dillon 	OS_REG_WRITE(ah, AR_ISR, isr);
221572ff6f6SMatthew Dillon 	/* Flush previous write */
222572ff6f6SMatthew Dillon 	OS_REG_READ(ah, AR_ISR);
223572ff6f6SMatthew Dillon 
224572ff6f6SMatthew Dillon 	if (AR_SREV_HOWL(ah))
225572ff6f6SMatthew Dillon 		return AH_TRUE;
226572ff6f6SMatthew Dillon 
227572ff6f6SMatthew Dillon 	if (sync_cause != 0) {
228572ff6f6SMatthew Dillon 		HALDEBUG(ah, HAL_DEBUG_INTERRUPT, "%s: sync_cause=0x%x\n",
229572ff6f6SMatthew Dillon 		    __func__,
230572ff6f6SMatthew Dillon 		    o_sync_cause);
231572ff6f6SMatthew Dillon 		if (sync_cause & (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR)) {
232572ff6f6SMatthew Dillon 			*masked |= HAL_INT_FATAL;
233572ff6f6SMatthew Dillon 		}
234572ff6f6SMatthew Dillon 		if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
235572ff6f6SMatthew Dillon 			HALDEBUG(ah, HAL_DEBUG_ANY, "%s: RADM CPL timeout\n",
236572ff6f6SMatthew Dillon 			    __func__);
237572ff6f6SMatthew Dillon 			OS_REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
238572ff6f6SMatthew Dillon 			OS_REG_WRITE(ah, AR_RC, 0);
239572ff6f6SMatthew Dillon 			*masked |= HAL_INT_FATAL;
240572ff6f6SMatthew Dillon 		}
241572ff6f6SMatthew Dillon 		/*
242572ff6f6SMatthew Dillon 		 * On fatal errors collect ISR state for debugging.
243572ff6f6SMatthew Dillon 		 */
244572ff6f6SMatthew Dillon 		if (*masked & HAL_INT_FATAL) {
245572ff6f6SMatthew Dillon 			AH_PRIVATE(ah)->ah_fatalState[0] = isr;
246572ff6f6SMatthew Dillon 			AH_PRIVATE(ah)->ah_fatalState[1] = sync_cause;
247572ff6f6SMatthew Dillon 			HALDEBUG(ah, HAL_DEBUG_ANY,
248572ff6f6SMatthew Dillon 			    "%s: fatal error, ISR_RAC 0x%x SYNC_CAUSE 0x%x\n",
249572ff6f6SMatthew Dillon 			    __func__, isr, sync_cause);
250572ff6f6SMatthew Dillon 		}
251572ff6f6SMatthew Dillon 
252572ff6f6SMatthew Dillon 		OS_REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
253572ff6f6SMatthew Dillon 		/* NB: flush write */
254572ff6f6SMatthew Dillon 		(void) OS_REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
255572ff6f6SMatthew Dillon 	}
256572ff6f6SMatthew Dillon 	return AH_TRUE;
257572ff6f6SMatthew Dillon }
258572ff6f6SMatthew Dillon 
259572ff6f6SMatthew Dillon /*
260572ff6f6SMatthew Dillon  * Atomically enables NIC interrupts.  Interrupts are passed in
261572ff6f6SMatthew Dillon  * via the enumerated bitmask in ints.
262572ff6f6SMatthew Dillon  */
263572ff6f6SMatthew Dillon HAL_INT
ar5416SetInterrupts(struct ath_hal * ah,HAL_INT ints)264572ff6f6SMatthew Dillon ar5416SetInterrupts(struct ath_hal *ah, HAL_INT ints)
265572ff6f6SMatthew Dillon {
266572ff6f6SMatthew Dillon 	struct ath_hal_5212 *ahp = AH5212(ah);
267572ff6f6SMatthew Dillon 	uint32_t omask = ahp->ah_maskReg;
268572ff6f6SMatthew Dillon 	uint32_t mask, mask2;
269572ff6f6SMatthew Dillon 
270572ff6f6SMatthew Dillon 	HALDEBUG(ah, HAL_DEBUG_INTERRUPT, "%s: 0x%x => 0x%x\n",
271572ff6f6SMatthew Dillon 	    __func__, omask, ints);
272572ff6f6SMatthew Dillon 
273572ff6f6SMatthew Dillon 	if (omask & HAL_INT_GLOBAL) {
274572ff6f6SMatthew Dillon 		HALDEBUG(ah, HAL_DEBUG_INTERRUPT, "%s: disable IER\n", __func__);
275572ff6f6SMatthew Dillon 		OS_REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
276572ff6f6SMatthew Dillon 		(void) OS_REG_READ(ah, AR_IER);
277572ff6f6SMatthew Dillon 
278572ff6f6SMatthew Dillon 		if (! AR_SREV_HOWL(ah)) {
279572ff6f6SMatthew Dillon 			OS_REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
280572ff6f6SMatthew Dillon 			(void) OS_REG_READ(ah, AR_INTR_ASYNC_ENABLE);
281572ff6f6SMatthew Dillon 
282572ff6f6SMatthew Dillon 			OS_REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
283572ff6f6SMatthew Dillon 			(void) OS_REG_READ(ah, AR_INTR_SYNC_ENABLE);
284572ff6f6SMatthew Dillon 		}
285572ff6f6SMatthew Dillon 	}
286572ff6f6SMatthew Dillon 
287572ff6f6SMatthew Dillon 	mask = ints & HAL_INT_COMMON;
288572ff6f6SMatthew Dillon 	mask2 = 0;
289572ff6f6SMatthew Dillon 
290572ff6f6SMatthew Dillon #ifdef	AH_AR5416_INTERRUPT_MITIGATION
291572ff6f6SMatthew Dillon 	/*
292572ff6f6SMatthew Dillon 	 * Overwrite default mask if Interrupt mitigation
293572ff6f6SMatthew Dillon 	 * is specified for AR5416
294572ff6f6SMatthew Dillon 	 */
295572ff6f6SMatthew Dillon 	if (ints & HAL_INT_RX)
296572ff6f6SMatthew Dillon 		mask |= AR_IMR_RXERR | AR_IMR_RXMINTR | AR_IMR_RXINTM;
297572ff6f6SMatthew Dillon #else
298572ff6f6SMatthew Dillon 	if (ints & HAL_INT_RX)
299572ff6f6SMatthew Dillon 		mask |= AR_IMR_RXOK | AR_IMR_RXERR | AR_IMR_RXDESC;
300572ff6f6SMatthew Dillon #endif
301572ff6f6SMatthew Dillon 	if (ints & HAL_INT_TX) {
302572ff6f6SMatthew Dillon 		if (ahp->ah_txOkInterruptMask)
303572ff6f6SMatthew Dillon 			mask |= AR_IMR_TXOK;
304572ff6f6SMatthew Dillon 		if (ahp->ah_txErrInterruptMask)
305572ff6f6SMatthew Dillon 			mask |= AR_IMR_TXERR;
306572ff6f6SMatthew Dillon 		if (ahp->ah_txDescInterruptMask)
307572ff6f6SMatthew Dillon 			mask |= AR_IMR_TXDESC;
308572ff6f6SMatthew Dillon 		if (ahp->ah_txEolInterruptMask)
309572ff6f6SMatthew Dillon 			mask |= AR_IMR_TXEOL;
310572ff6f6SMatthew Dillon 		if (ahp->ah_txUrnInterruptMask)
311572ff6f6SMatthew Dillon 			mask |= AR_IMR_TXURN;
312572ff6f6SMatthew Dillon 	}
313572ff6f6SMatthew Dillon 	if (ints & (HAL_INT_BMISC)) {
314572ff6f6SMatthew Dillon 		mask |= AR_IMR_BCNMISC;
315572ff6f6SMatthew Dillon 		if (ints & HAL_INT_TIM)
316572ff6f6SMatthew Dillon 			mask2 |= AR_IMR_S2_TIM;
317572ff6f6SMatthew Dillon 		if (ints & HAL_INT_DTIM)
318572ff6f6SMatthew Dillon 			mask2 |= AR_IMR_S2_DTIM;
319572ff6f6SMatthew Dillon 		if (ints & HAL_INT_DTIMSYNC)
320572ff6f6SMatthew Dillon 			mask2 |= AR_IMR_S2_DTIMSYNC;
321572ff6f6SMatthew Dillon 		if (ints & HAL_INT_CABEND)
322572ff6f6SMatthew Dillon 			mask2 |= (AR_IMR_S2_CABEND );
323572ff6f6SMatthew Dillon 		if (ints & HAL_INT_CST)
324572ff6f6SMatthew Dillon 			mask2 |= AR_IMR_S2_CST;
325572ff6f6SMatthew Dillon 		if (ints & HAL_INT_TSFOOR)
326572ff6f6SMatthew Dillon 			mask2 |= AR_IMR_S2_TSFOOR;
327572ff6f6SMatthew Dillon 	}
328572ff6f6SMatthew Dillon 
329572ff6f6SMatthew Dillon 	if (ints & (HAL_INT_GTT | HAL_INT_CST)) {
330572ff6f6SMatthew Dillon 		mask |= AR_IMR_BCNMISC;
331572ff6f6SMatthew Dillon 		if (ints & HAL_INT_GTT)
332572ff6f6SMatthew Dillon 			mask2 |= AR_IMR_S2_GTT;
333572ff6f6SMatthew Dillon 		if (ints & HAL_INT_CST)
334572ff6f6SMatthew Dillon 			mask2 |= AR_IMR_S2_CST;
335572ff6f6SMatthew Dillon 	}
336572ff6f6SMatthew Dillon 
337572ff6f6SMatthew Dillon 	/* Write the new IMR and store off our SW copy. */
338572ff6f6SMatthew Dillon 	HALDEBUG(ah, HAL_DEBUG_INTERRUPT, "%s: new IMR 0x%x\n", __func__, mask);
339572ff6f6SMatthew Dillon 	OS_REG_WRITE(ah, AR_IMR, mask);
340*d98a0bcfSMatthew Dillon 	/* Flush write */
341*d98a0bcfSMatthew Dillon 	(void) OS_REG_READ(ah, AR_IMR);
342*d98a0bcfSMatthew Dillon 
343572ff6f6SMatthew Dillon 	mask = OS_REG_READ(ah, AR_IMR_S2) & ~(AR_IMR_S2_TIM |
344572ff6f6SMatthew Dillon 					AR_IMR_S2_DTIM |
345572ff6f6SMatthew Dillon 					AR_IMR_S2_DTIMSYNC |
346572ff6f6SMatthew Dillon 					AR_IMR_S2_CABEND |
347572ff6f6SMatthew Dillon 					AR_IMR_S2_CABTO  |
348572ff6f6SMatthew Dillon 					AR_IMR_S2_TSFOOR |
349572ff6f6SMatthew Dillon 					AR_IMR_S2_GTT |
350572ff6f6SMatthew Dillon 					AR_IMR_S2_CST);
351572ff6f6SMatthew Dillon 	OS_REG_WRITE(ah, AR_IMR_S2, mask | mask2);
352572ff6f6SMatthew Dillon 
353572ff6f6SMatthew Dillon 	ahp->ah_maskReg = ints;
354572ff6f6SMatthew Dillon 
355572ff6f6SMatthew Dillon 	/* Re-enable interrupts if they were enabled before. */
356572ff6f6SMatthew Dillon 	if (ints & HAL_INT_GLOBAL) {
357572ff6f6SMatthew Dillon 		HALDEBUG(ah, HAL_DEBUG_INTERRUPT, "%s: enable IER\n", __func__);
358572ff6f6SMatthew Dillon 		OS_REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
359572ff6f6SMatthew Dillon 
360572ff6f6SMatthew Dillon 		if (! AR_SREV_HOWL(ah)) {
361572ff6f6SMatthew Dillon 			mask = AR_INTR_MAC_IRQ;
362572ff6f6SMatthew Dillon 			if (ints & HAL_INT_GPIO)
363572ff6f6SMatthew Dillon 				mask |= SM(AH5416(ah)->ah_gpioMask,
364572ff6f6SMatthew Dillon 				    AR_INTR_ASYNC_MASK_GPIO);
365572ff6f6SMatthew Dillon 			OS_REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, mask);
366572ff6f6SMatthew Dillon 			OS_REG_WRITE(ah, AR_INTR_ASYNC_MASK, mask);
367572ff6f6SMatthew Dillon 
368572ff6f6SMatthew Dillon 			mask = AR_INTR_SYNC_DEFAULT;
369572ff6f6SMatthew Dillon 			if (ints & HAL_INT_GPIO)
370572ff6f6SMatthew Dillon 				mask |= SM(AH5416(ah)->ah_gpioMask,
371572ff6f6SMatthew Dillon 				    AR_INTR_SYNC_MASK_GPIO);
372572ff6f6SMatthew Dillon 			OS_REG_WRITE(ah, AR_INTR_SYNC_ENABLE, mask);
373572ff6f6SMatthew Dillon 			OS_REG_WRITE(ah, AR_INTR_SYNC_MASK, mask);
374572ff6f6SMatthew Dillon 		}
375572ff6f6SMatthew Dillon 	}
376572ff6f6SMatthew Dillon 
377572ff6f6SMatthew Dillon 	return omask;
378572ff6f6SMatthew Dillon }
379