FreeBSD kernel ATH device code
ar5416_interrupts.c
Go to the documentation of this file.
1/*-
2 * SPDX-License-Identifier: ISC
3 *
4 * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
5 * Copyright (c) 2002-2008 Atheros Communications, Inc.
6 *
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.
10 *
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.
18 *
19 * $FreeBSD$
20 */
21#include "opt_ah.h"
22
23#include "ah.h"
24#include "ah_internal.h"
25
26#include "ar5416/ar5416.h"
27#include "ar5416/ar5416reg.h"
28
29/*
30 * Checks to see if an interrupt is pending on our NIC
31 *
32 * Returns: TRUE if an interrupt is pending
33 * FALSE if not
34 */
37{
38 uint32_t isr;
39
40 if (AR_SREV_HOWL(ah))
41 return AH_TRUE;
42
43 /*
44 * Some platforms trigger our ISR before applying power to
45 * the card, so make sure the INTPEND is really 1, not 0xffffffff.
46 */
48 if (isr != AR_INTR_SPURIOUS && (isr & AR_INTR_MAC_IRQ) != 0)
49 return AH_TRUE;
50
52 if (isr != AR_INTR_SPURIOUS && (isr & AR_INTR_SYNC_DEFAULT))
53 return AH_TRUE;
54
55 return AH_FALSE;
56}
57
58/*
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.
63 *
64 * (*masked) is cleared on initial call.
65 *
66 * Returns: A hardware-abstracted bitmap of all non-masked-out
67 * interrupts pending, as well as an unmasked value
68 */
71{
72 uint32_t isr, isr0, isr1, sync_cause = 0, o_sync_cause = 0;
73 HAL_CAPABILITIES *pCap = &AH_PRIVATE(ah)->ah_caps;
74
75#ifdef AH_INTERRUPT_DEBUGGING
76 /*
77 * Blank the interrupt debugging area regardless.
78 */
79 bzero(&ah->ah_intrstate, sizeof(ah->ah_intrstate));
80 ah->ah_syncstate = 0;
81#endif
82
83 /*
84 * Verify there's a mac interrupt and the RTC is on.
85 */
86 if (AR_SREV_HOWL(ah)) {
87 *masked = 0;
88 isr = OS_REG_READ(ah, AR_ISR);
89 } else {
92 isr = OS_REG_READ(ah, AR_ISR);
93 else
94 isr = 0;
95#ifdef AH_INTERRUPT_DEBUGGING
96 ah->ah_syncstate =
97#endif
98 o_sync_cause = sync_cause = OS_REG_READ(ah, AR_INTR_SYNC_CAUSE);
99 sync_cause &= AR_INTR_SYNC_DEFAULT;
100 *masked = 0;
101
102 if (isr == 0 && sync_cause == 0)
103 return AH_FALSE;
104 }
105
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);
114#endif
115
116 if (isr != 0) {
117 struct ath_hal_5212 *ahp = AH5212(ah);
118 uint32_t mask2;
119
120 mask2 = 0;
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;
137
138 /*
139 * Don't mask out AR_BCNMISC; instead mask
140 * out what causes it.
141 */
142 OS_REG_WRITE(ah, AR_ISR_S2, isr2);
143 isr &= ~AR_ISR_BCNMISC;
144 }
145
146 if (isr == 0xffffffff) {
147 *masked = 0;
148 return AH_FALSE;
149 }
150
151 *masked = isr & HAL_INT_COMMON;
152
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;
157
158 /*
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.
164 *
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.
169 */
170#ifdef AH_AR5416_INTERRUPT_MITIGATION
171 if (isr & AR_ISR_RXERR)
172 *masked |= HAL_INT_RX;
173#else
174 if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
175 *masked |= HAL_INT_RX;
176#endif
177
178 if (isr & (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
179 AR_ISR_TXEOL)) {
180 *masked |= HAL_INT_TX;
181
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);
186
187 /*
188 * Don't clear the primary ISR TX bits, clear
189 * what causes them (S0/S1.)
190 */
191 isr &= ~(AR_ISR_TXOK | AR_ISR_TXDESC |
193
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);
198 }
199
200 if ((isr & AR_ISR_GENTMR) || (! pCap->halAutoSleepSupport)) {
201 uint32_t isr5;
202 isr5 = OS_REG_READ(ah, AR_ISR_S5);
203 OS_REG_WRITE(ah, AR_ISR_S5, isr5);
204 isr &= ~AR_ISR_GENTMR;
205
206 if (! pCap->halAutoSleepSupport)
207 if (isr5 & AR_ISR_S5_TIM_TIMER)
208 *masked |= HAL_INT_TIM_TIMER;
209 }
210 *masked |= mask2;
211 }
212
213 /*
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.
221 */
222 OS_REG_WRITE(ah, AR_ISR, isr);
223 /* Flush previous write */
224 OS_REG_READ(ah, AR_ISR);
225
226 if (AR_SREV_HOWL(ah))
227 return AH_TRUE;
228
229 if (sync_cause != 0) {
230 HALDEBUG(ah, HAL_DEBUG_INTERRUPT, "%s: sync_cause=0x%x\n",
231 __func__,
232 o_sync_cause);
234 *masked |= HAL_INT_FATAL;
235 }
236 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
237 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: RADM CPL timeout\n",
238 __func__);
240 OS_REG_WRITE(ah, AR_RC, 0);
241 *masked |= HAL_INT_FATAL;
242 }
243 /*
244 * On fatal errors collect ISR state for debugging.
245 */
246 if (*masked & HAL_INT_FATAL) {
247 AH_PRIVATE(ah)->ah_fatalState[0] = isr;
248 AH_PRIVATE(ah)->ah_fatalState[1] = sync_cause;
250 "%s: fatal error, ISR_RAC 0x%x SYNC_CAUSE 0x%x\n",
251 __func__, isr, sync_cause);
252 }
253
254 OS_REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
255 /* NB: flush write */
257 }
258 return AH_TRUE;
259}
260
261/*
262 * Atomically enables NIC interrupts. Interrupts are passed in
263 * via the enumerated bitmask in ints.
264 */
267{
268 struct ath_hal_5212 *ahp = AH5212(ah);
269 uint32_t omask = ahp->ah_maskReg;
270 uint32_t mask, mask2;
271
272 HALDEBUG(ah, HAL_DEBUG_INTERRUPT, "%s: 0x%x => 0x%x\n",
273 __func__, omask, ints);
274
275 if (omask & HAL_INT_GLOBAL) {
276 HALDEBUG(ah, HAL_DEBUG_INTERRUPT, "%s: disable IER\n", __func__);
278 (void) OS_REG_READ(ah, AR_IER);
279
280 if (! AR_SREV_HOWL(ah)) {
283
286 }
287 }
288
289 mask = ints & HAL_INT_COMMON;
290 mask2 = 0;
291
292#ifdef AH_AR5416_INTERRUPT_MITIGATION
293 /*
294 * Overwrite default mask if Interrupt mitigation
295 * is specified for AR5416
296 */
297 if (ints & HAL_INT_RX)
299#else
300 if (ints & HAL_INT_RX)
302#endif
303 if (ints & HAL_INT_TX) {
304 if (ahp->ah_txOkInterruptMask)
305 mask |= AR_IMR_TXOK;
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;
314 }
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;
329 }
330
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;
337 }
338
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);
342 /* Flush write */
343 (void) OS_REG_READ(ah, AR_IMR);
344
345 mask = OS_REG_READ(ah, AR_IMR_S2) & ~(AR_IMR_S2_TIM |
353 OS_REG_WRITE(ah, AR_IMR_S2, mask | mask2);
354
355 ahp->ah_maskReg = ints;
356
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__);
361
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,
369
371 if (ints & HAL_INT_GPIO)
372 mask |= SM(AH5416(ah)->ah_gpioMask,
376 }
377 }
378
379 return omask;
380}
#define HAL_INT_GLOBAL
Definition: ah.h:506
HAL_INT
Definition: ah.h:472
@ HAL_INT_TIM
Definition: ah.h:494
@ HAL_INT_GTT
Definition: ah.h:504
@ HAL_INT_COMMON
Definition: ah.h:514
@ HAL_INT_DTIM
Definition: ah.h:495
@ HAL_INT_FATAL
Definition: ah.h:505
@ HAL_INT_GPIO
Definition: ah.h:497
@ HAL_INT_TX
Definition: ah.h:481
@ HAL_INT_CABEND
Definition: ah.h:498
@ HAL_INT_DTIMSYNC
Definition: ah.h:496
@ HAL_INT_CST
Definition: ah.h:503
@ HAL_INT_RX
Definition: ah.h:473
@ HAL_INT_TSFOOR
Definition: ah.h:499
@ HAL_INT_BMISC
Definition: ah.h:507
@ HAL_INT_TIM_TIMER
Definition: ah.h:483
HAL_BOOL
Definition: ah.h:93
@ AH_FALSE
Definition: ah.h:94
@ AH_TRUE
Definition: ah.h:95
@ HAL_DEBUG_ANY
Definition: ah_debug.h:62
@ HAL_DEBUG_INTERRUPT
Definition: ah_debug.h:48
#define SM(_v, _f)
Definition: ah_internal.h:587
#define MS(_v, _f)
Definition: ah_internal.h:588
#define AH_PRIVATE(_ah)
Definition: ah_internal.h:442
#define HALDEBUG(_ah, __m,...)
Definition: ah_internal.h:658
#define OS_REG_WRITE(_ah, _reg, _val)
Definition: ah_osdep.h:139
#define OS_REG_READ(_ah, _reg)
Definition: ah_osdep.h:140
#define AR_ISR
Definition: ar5210reg.h:41
#define AR_IER_ENABLE
Definition: ar5210reg.h:187
#define AR_IER_DISABLE
Definition: ar5210reg.h:186
#define AR_IMR
Definition: ar5210reg.h:42
#define AR_RC
Definition: ar5210reg.h:55
#define AR_IER
Definition: ar5210reg.h:43
#define AR_ISR_S3
Definition: ar5211reg.h:55
#define AR_IMR_TXERR
Definition: ar5211reg.h:427
#define AR_ISR_S2
Definition: ar5211reg.h:54
#define AR_IMR_RXERR
Definition: ar5211reg.h:421
#define AR_ISR_S0
Definition: ar5211reg.h:52
#define AR_ISR_S4
Definition: ar5211reg.h:56
#define AR_ISR_TXDESC
Definition: ar5211reg.h:379
#define AR_IMR_TXEOL
Definition: ar5211reg.h:429
#define AR_ISR_TXEOL
Definition: ar5211reg.h:382
#define AR_ISR_S1
Definition: ar5211reg.h:53
#define AR_IMR_S2
Definition: ar5211reg.h:60
#define AR_IMR_TXURN
Definition: ar5211reg.h:430
#define AR_ISR_TXOK
Definition: ar5211reg.h:378
#define AR_ISR_TXERR
Definition: ar5211reg.h:380
#define AR_IMR_RXDESC
Definition: ar5211reg.h:420
#define AR_ISR_RXOK
Definition: ar5211reg.h:372
#define AR_ISR_RXERR
Definition: ar5211reg.h:374
#define AR_IMR_TXDESC
Definition: ar5211reg.h:426
#define AR_IMR_TXOK
Definition: ar5211reg.h:425
#define AR_IMR_RXOK
Definition: ar5211reg.h:419
#define AH5212(_ah)
Definition: ar5212.h:354
#define AR_IMR_S2_TSFOOR
Definition: ar5212reg.h:539
#define AR_ISR_S0_QCU_TXOK
Definition: ar5212reg.h:450
#define AR_IMR_BCNMISC
Definition: ar5212reg.h:510
#define AR_ISR_S0_QCU_TXDESC
Definition: ar5212reg.h:452
#define AR_ISR_S1_QCU_TXERR
Definition: ar5212reg.h:455
#define AR_ISR_S2_DTIMSYNC
Definition: ar5212reg.h:466
#define AR_ISR_S2_TSFOOR
Definition: ar5212reg.h:470
#define AR_ISR_S2_CABEND
Definition: ar5212reg.h:465
#define AR_ISR_S2_TIM
Definition: ar5212reg.h:464
#define AR_IMR_S2_CABTO
Definition: ar5212reg.h:537
#define AR_IMR_S2_DTIM
Definition: ar5212reg.h:538
#define AR_IMR_S2_TIM
Definition: ar5212reg.h:533
#define AR_ISR_S2_DTIM
Definition: ar5212reg.h:469
#define AR_ISR_BCNMISC
Definition: ar5212reg.h:442
#define AR_ISR_S1_QCU_TXEOL
Definition: ar5212reg.h:457
#define AR_IMR_S2_CABEND
Definition: ar5212reg.h:534
#define AR_IMR_S2_DTIMSYNC
Definition: ar5212reg.h:535
#define AH5416(_ah)
Definition: ar5416.h:162
HAL_BOOL ar5416GetPendingInterrupts(struct ath_hal *ah, HAL_INT *masked)
HAL_INT ar5416SetInterrupts(struct ath_hal *ah, HAL_INT ints)
HAL_BOOL ar5416IsInterruptPending(struct ath_hal *ah)
#define AR_RTC_STATUS_M
Definition: ar5416reg.h:416
#define AR_INTR_SYNC_HOST1_PERR
Definition: ar5416reg.h:353
#define AR_INTR_SYNC_MASK_GPIO
Definition: ar5416reg.h:375
#define AR_INTR_SYNC_RADM_CPL_TIMEOUT
Definition: ar5416reg.h:359
#define AR_RC_HOSTIF
Definition: ar5416reg.h:191
#define AR_ISR_TXINTM
Definition: ar5416reg.h:313
#define AR_ISR_RXMINTR
Definition: ar5416reg.h:311
#define AR_INTR_MAC_IRQ
Definition: ar5416reg.h:332
#define AR_ISR_RXINTM
Definition: ar5416reg.h:314
#define AR_ISR_TXMINTR
Definition: ar5416reg.h:310
#define AR_IMR_S2_GTT
Definition: ar5416reg.h:344
#define AR_INTR_SPURIOUS
Definition: ar5416reg.h:330
#define AR_INTR_ASYNC_ENABLE
Definition: ar5416reg.h:46
#define AR_IMR_S2_CST
Definition: ar5416reg.h:343
#define AR_INTR_SYNC_HOST1_FATAL
Definition: ar5416reg.h:352
#define AR_INTR_SYNC_MASK
Definition: ar5416reg.h:43
#define AR_ISR_S5
Definition: ar5416reg.h:320
#define AR_ISR_GENTMR
Definition: ar5416reg.h:312
#define AR_ISR_S2_CST
Definition: ar5416reg.h:316
#define AR_INTR_ASYNC_MASK_GPIO
Definition: ar5416reg.h:381
#define AR_ISR_S2_GTT
Definition: ar5416reg.h:317
#define AR_INTR_ASYNC_CAUSE
Definition: ar5416reg.h:44
#define AR_INTR_SYNC_CAUSE_CLR
Definition: ar5416reg.h:39
#define AR_INTR_ASYNC_MASK
Definition: ar5416reg.h:42
#define AR_INTR_SYNC_CAUSE
Definition: ar5416reg.h:40
#define AR_SREV_HOWL(_ah)
Definition: ar5416reg.h:718
#define AR_RTC_STATUS_ON
Definition: ar5416reg.h:419
#define AR_ISR_S5_TIM_TIMER
Definition: ar5416reg.h:323
#define AR_INTR_SYNC_ENABLE
Definition: ar5416reg.h:41
#define AR_INTR_SYNC_DEFAULT
Definition: ar5416reg.h:368
#define AR_IMR_RXINTM
Definition: ar5416reg.h:341
#define AR_IMR_RXMINTR
Definition: ar5416reg.h:339
#define AR_RTC_STATUS
Definition: ar5416reg.h:114
uint32_t halAutoSleepSupport
Definition: ah_internal.h:251
uint32_t ah_txUrnInterruptMask
Definition: ar5212.h:272
uint32_t ah_txEolInterruptMask
Definition: ar5212.h:271
uint32_t ah_txDescInterruptMask
Definition: ar5212.h:270
uint32_t ah_maskReg
Definition: ar5212.h:264
uint32_t ah_txOkInterruptMask
Definition: ar5212.h:268
uint32_t ah_txErrInterruptMask
Definition: ar5212.h:269
uint32_t ah_intrTxqs
Definition: ar5212.h:274
Definition: ah.h:1219
uint32_t ah_syncstate
Definition: ah.h:1238
uint32_t ah_intrstate[8]
Definition: ah.h:1237