2 * SPDX-License-Identifier: ISC
4 * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
5 * Copyright (c) 2002-2008 Atheros Communications, Inc.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 #include "ah_internal.h"
26 #include "ar5416/ar5416.h"
27 #include "ar5416/ar5416reg.h"
30 * Checks to see if an interrupt is pending on our NIC
32 * Returns: TRUE if an interrupt is pending
36 ar5416IsInterruptPending(struct ath_hal *ah)
44 * Some platforms trigger our ISR before applying power to
45 * the card, so make sure the INTPEND is really 1, not 0xffffffff.
47 isr = OS_REG_READ(ah, AR_INTR_ASYNC_CAUSE);
48 if (isr != AR_INTR_SPURIOUS && (isr & AR_INTR_MAC_IRQ) != 0)
51 isr = OS_REG_READ(ah, AR_INTR_SYNC_CAUSE);
52 if (isr != AR_INTR_SPURIOUS && (isr & AR_INTR_SYNC_DEFAULT))
59 * Reads the Interrupt Status Register value from the NIC, thus deasserting
60 * the interrupt line, and returns both the masked and unmasked mapped ISR
61 * values. The value returned is mapped to abstract the hw-specific bit
62 * locations in the Interrupt Status Register.
64 * (*masked) is cleared on initial call.
66 * Returns: A hardware-abstracted bitmap of all non-masked-out
67 * interrupts pending, as well as an unmasked value
70 ar5416GetPendingInterrupts(struct ath_hal *ah, HAL_INT *masked)
72 uint32_t isr, isr0, isr1, sync_cause = 0, o_sync_cause = 0;
73 HAL_CAPABILITIES *pCap = &AH_PRIVATE(ah)->ah_caps;
75 #ifdef AH_INTERRUPT_DEBUGGING
77 * Blank the interrupt debugging area regardless.
79 bzero(&ah->ah_intrstate, sizeof(ah->ah_intrstate));
84 * Verify there's a mac interrupt and the RTC is on.
86 if (AR_SREV_HOWL(ah)) {
88 isr = OS_REG_READ(ah, AR_ISR);
90 if ((OS_REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) &&
91 (OS_REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M) == AR_RTC_STATUS_ON)
92 isr = OS_REG_READ(ah, AR_ISR);
95 #ifdef AH_INTERRUPT_DEBUGGING
98 o_sync_cause = sync_cause = OS_REG_READ(ah, AR_INTR_SYNC_CAUSE);
99 sync_cause &= AR_INTR_SYNC_DEFAULT;
102 if (isr == 0 && sync_cause == 0)
106 #ifdef AH_INTERRUPT_DEBUGGING
107 ah->ah_intrstate[0] = isr;
108 ah->ah_intrstate[1] = OS_REG_READ(ah, AR_ISR_S0);
109 ah->ah_intrstate[2] = OS_REG_READ(ah, AR_ISR_S1);
110 ah->ah_intrstate[3] = OS_REG_READ(ah, AR_ISR_S2);
111 ah->ah_intrstate[4] = OS_REG_READ(ah, AR_ISR_S3);
112 ah->ah_intrstate[5] = OS_REG_READ(ah, AR_ISR_S4);
113 ah->ah_intrstate[6] = OS_REG_READ(ah, AR_ISR_S5);
117 struct ath_hal_5212 *ahp = AH5212(ah);
121 if (isr & AR_ISR_BCNMISC) {
122 uint32_t isr2 = OS_REG_READ(ah, AR_ISR_S2);
123 if (isr2 & AR_ISR_S2_TIM)
124 mask2 |= HAL_INT_TIM;
125 if (isr2 & AR_ISR_S2_DTIM)
126 mask2 |= HAL_INT_DTIM;
127 if (isr2 & AR_ISR_S2_DTIMSYNC)
128 mask2 |= HAL_INT_DTIMSYNC;
129 if (isr2 & (AR_ISR_S2_CABEND ))
130 mask2 |= HAL_INT_CABEND;
131 if (isr2 & AR_ISR_S2_GTT)
132 mask2 |= HAL_INT_GTT;
133 if (isr2 & AR_ISR_S2_CST)
134 mask2 |= HAL_INT_CST;
135 if (isr2 & AR_ISR_S2_TSFOOR)
136 mask2 |= HAL_INT_TSFOOR;
139 * Don't mask out AR_BCNMISC; instead mask
140 * out what causes it.
142 OS_REG_WRITE(ah, AR_ISR_S2, isr2);
143 isr &= ~AR_ISR_BCNMISC;
146 if (isr == 0xffffffff) {
151 *masked = isr & HAL_INT_COMMON;
153 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
154 *masked |= HAL_INT_RX;
155 if (isr & (AR_ISR_TXMINTR | AR_ISR_TXINTM))
156 *masked |= HAL_INT_TX;
159 * When doing RX interrupt mitigation, the RXOK bit is set
160 * in AR_ISR even if the relevant bit in AR_IMR is clear.
161 * Since this interrupt may be due to another source, don't
162 * just automatically set HAL_INT_RX if it's set, otherwise
163 * we could prematurely service the RX queue.
165 * In some cases, the driver can even handle all the RX
166 * frames just before the mitigation interrupt fires.
167 * The subsequent RX processing trip will then end up
168 * processing 0 frames.
170 #ifdef AH_AR5416_INTERRUPT_MITIGATION
171 if (isr & AR_ISR_RXERR)
172 *masked |= HAL_INT_RX;
174 if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
175 *masked |= HAL_INT_RX;
178 if (isr & (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
180 *masked |= HAL_INT_TX;
182 isr0 = OS_REG_READ(ah, AR_ISR_S0);
183 OS_REG_WRITE(ah, AR_ISR_S0, isr0);
184 isr1 = OS_REG_READ(ah, AR_ISR_S1);
185 OS_REG_WRITE(ah, AR_ISR_S1, isr1);
188 * Don't clear the primary ISR TX bits, clear
189 * what causes them (S0/S1.)
191 isr &= ~(AR_ISR_TXOK | AR_ISR_TXDESC |
192 AR_ISR_TXERR | AR_ISR_TXEOL);
194 ahp->ah_intrTxqs |= MS(isr0, AR_ISR_S0_QCU_TXOK);
195 ahp->ah_intrTxqs |= MS(isr0, AR_ISR_S0_QCU_TXDESC);
196 ahp->ah_intrTxqs |= MS(isr1, AR_ISR_S1_QCU_TXERR);
197 ahp->ah_intrTxqs |= MS(isr1, AR_ISR_S1_QCU_TXEOL);
200 if ((isr & AR_ISR_GENTMR) || (! pCap->halAutoSleepSupport)) {
202 isr5 = OS_REG_READ(ah, AR_ISR_S5);
203 OS_REG_WRITE(ah, AR_ISR_S5, isr5);
204 isr &= ~AR_ISR_GENTMR;
206 if (! pCap->halAutoSleepSupport)
207 if (isr5 & AR_ISR_S5_TIM_TIMER)
208 *masked |= HAL_INT_TIM_TIMER;
214 * Since we're not using AR_ISR_RAC, clear the status bits
215 * for handled interrupts here. For bits whose interrupt
216 * source is a secondary register, those bits should've been
217 * masked out - instead of those bits being written back,
218 * their source (ie, the secondary status registers) should
219 * be cleared. That way there are no race conditions with
220 * new triggers coming in whilst they've been read/cleared.
222 OS_REG_WRITE(ah, AR_ISR, isr);
223 /* Flush previous write */
224 OS_REG_READ(ah, AR_ISR);
226 if (AR_SREV_HOWL(ah))
229 if (sync_cause != 0) {
230 HALDEBUG(ah, HAL_DEBUG_INTERRUPT, "%s: sync_cause=0x%x\n",
233 if (sync_cause & (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR)) {
234 *masked |= HAL_INT_FATAL;
236 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
237 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: RADM CPL timeout\n",
239 OS_REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
240 OS_REG_WRITE(ah, AR_RC, 0);
241 *masked |= HAL_INT_FATAL;
244 * On fatal errors collect ISR state for debugging.
246 if (*masked & HAL_INT_FATAL) {
247 AH_PRIVATE(ah)->ah_fatalState[0] = isr;
248 AH_PRIVATE(ah)->ah_fatalState[1] = sync_cause;
249 HALDEBUG(ah, HAL_DEBUG_ANY,
250 "%s: fatal error, ISR_RAC 0x%x SYNC_CAUSE 0x%x\n",
251 __func__, isr, sync_cause);
254 OS_REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
255 /* NB: flush write */
256 (void) OS_REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
262 * Atomically enables NIC interrupts. Interrupts are passed in
263 * via the enumerated bitmask in ints.
266 ar5416SetInterrupts(struct ath_hal *ah, HAL_INT ints)
268 struct ath_hal_5212 *ahp = AH5212(ah);
269 uint32_t omask = ahp->ah_maskReg;
270 uint32_t mask, mask2;
272 HALDEBUG(ah, HAL_DEBUG_INTERRUPT, "%s: 0x%x => 0x%x\n",
273 __func__, omask, ints);
275 if (omask & HAL_INT_GLOBAL) {
276 HALDEBUG(ah, HAL_DEBUG_INTERRUPT, "%s: disable IER\n", __func__);
277 OS_REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
278 (void) OS_REG_READ(ah, AR_IER);
280 if (! AR_SREV_HOWL(ah)) {
281 OS_REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
282 (void) OS_REG_READ(ah, AR_INTR_ASYNC_ENABLE);
284 OS_REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
285 (void) OS_REG_READ(ah, AR_INTR_SYNC_ENABLE);
289 mask = ints & HAL_INT_COMMON;
292 #ifdef AH_AR5416_INTERRUPT_MITIGATION
294 * Overwrite default mask if Interrupt mitigation
295 * is specified for AR5416
297 if (ints & HAL_INT_RX)
298 mask |= AR_IMR_RXERR | AR_IMR_RXMINTR | AR_IMR_RXINTM;
300 if (ints & HAL_INT_RX)
301 mask |= AR_IMR_RXOK | AR_IMR_RXERR | AR_IMR_RXDESC;
303 if (ints & HAL_INT_TX) {
304 if (ahp->ah_txOkInterruptMask)
306 if (ahp->ah_txErrInterruptMask)
307 mask |= AR_IMR_TXERR;
308 if (ahp->ah_txDescInterruptMask)
309 mask |= AR_IMR_TXDESC;
310 if (ahp->ah_txEolInterruptMask)
311 mask |= AR_IMR_TXEOL;
312 if (ahp->ah_txUrnInterruptMask)
313 mask |= AR_IMR_TXURN;
315 if (ints & (HAL_INT_BMISC)) {
316 mask |= AR_IMR_BCNMISC;
317 if (ints & HAL_INT_TIM)
318 mask2 |= AR_IMR_S2_TIM;
319 if (ints & HAL_INT_DTIM)
320 mask2 |= AR_IMR_S2_DTIM;
321 if (ints & HAL_INT_DTIMSYNC)
322 mask2 |= AR_IMR_S2_DTIMSYNC;
323 if (ints & HAL_INT_CABEND)
324 mask2 |= (AR_IMR_S2_CABEND );
325 if (ints & HAL_INT_CST)
326 mask2 |= AR_IMR_S2_CST;
327 if (ints & HAL_INT_TSFOOR)
328 mask2 |= AR_IMR_S2_TSFOOR;
331 if (ints & (HAL_INT_GTT | HAL_INT_CST)) {
332 mask |= AR_IMR_BCNMISC;
333 if (ints & HAL_INT_GTT)
334 mask2 |= AR_IMR_S2_GTT;
335 if (ints & HAL_INT_CST)
336 mask2 |= AR_IMR_S2_CST;
339 /* Write the new IMR and store off our SW copy. */
340 HALDEBUG(ah, HAL_DEBUG_INTERRUPT, "%s: new IMR 0x%x\n", __func__, mask);
341 OS_REG_WRITE(ah, AR_IMR, mask);
343 (void) OS_REG_READ(ah, AR_IMR);
345 mask = OS_REG_READ(ah, AR_IMR_S2) & ~(AR_IMR_S2_TIM |
353 OS_REG_WRITE(ah, AR_IMR_S2, mask | mask2);
355 ahp->ah_maskReg = ints;
357 /* Re-enable interrupts if they were enabled before. */
358 if (ints & HAL_INT_GLOBAL) {
359 HALDEBUG(ah, HAL_DEBUG_INTERRUPT, "%s: enable IER\n", __func__);
360 OS_REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
362 if (! AR_SREV_HOWL(ah)) {
363 mask = AR_INTR_MAC_IRQ;
364 if (ints & HAL_INT_GPIO)
365 mask |= SM(AH5416(ah)->ah_gpioMask,
366 AR_INTR_ASYNC_MASK_GPIO);
367 OS_REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, mask);
368 OS_REG_WRITE(ah, AR_INTR_ASYNC_MASK, mask);
370 mask = AR_INTR_SYNC_DEFAULT;
371 if (ints & HAL_INT_GPIO)
372 mask |= SM(AH5416(ah)->ah_gpioMask,
373 AR_INTR_SYNC_MASK_GPIO);
374 OS_REG_WRITE(ah, AR_INTR_SYNC_ENABLE, mask);
375 OS_REG_WRITE(ah, AR_INTR_SYNC_MASK, mask);