Path: blob/main/sys/dev/ath/ath_hal/ar5211/ar5211_interrupts.c
39566 views
/*-1* SPDX-License-Identifier: ISC2*3* Copyright (c) 2002-2008 Sam Leffler, Errno Consulting4* Copyright (c) 2002-2006 Atheros Communications, Inc.5*6* Permission to use, copy, modify, and/or distribute this software for any7* purpose with or without fee is hereby granted, provided that the above8* copyright notice and this permission notice appear in all copies.9*10* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES11* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF12* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR13* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES14* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN15* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF16* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.17*/18#include "opt_ah.h"1920#include "ah.h"21#include "ah_internal.h"2223#include "ar5211/ar5211.h"24#include "ar5211/ar5211reg.h"2526/*27* Checks to see if an interrupt is pending on our NIC28*29* Returns: TRUE if an interrupt is pending30* FALSE if not31*/32HAL_BOOL33ar5211IsInterruptPending(struct ath_hal *ah)34{35return OS_REG_READ(ah, AR_INTPEND) != 0;36}3738/*39* Reads the Interrupt Status Register value from the NIC, thus deasserting40* the interrupt line, and returns both the masked and unmasked mapped ISR41* values. The value returned is mapped to abstract the hw-specific bit42* locations in the Interrupt Status Register.43*44* Returns: A hardware-abstracted bitmap of all non-masked-out45* interrupts pending, as well as an unmasked value46*/47HAL_BOOL48ar5211GetPendingInterrupts(struct ath_hal *ah, HAL_INT *masked)49{50uint32_t isr;5152isr = OS_REG_READ(ah, AR_ISR_RAC);53if (isr == 0xffffffff) {54*masked = 0;55return AH_FALSE;56}5758*masked = isr & HAL_INT_COMMON;5960if (isr & AR_ISR_HIUERR)61*masked |= HAL_INT_FATAL;62if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))63*masked |= HAL_INT_RX;64if (isr & (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR | AR_ISR_TXEOL))65*masked |= HAL_INT_TX;66/*67* Receive overrun is usually non-fatal on Oahu/Spirit.68* BUT on some parts rx could fail and the chip must be reset.69* So we force a hardware reset in all cases.70*/71if ((isr & AR_ISR_RXORN) && AH_PRIVATE(ah)->ah_rxornIsFatal) {72HALDEBUG(ah, HAL_DEBUG_ANY,73"%s: receive FIFO overrun interrupt\n", __func__);74*masked |= HAL_INT_FATAL;75}7677/*78* On fatal errors collect ISR state for debugging.79*/80if (*masked & HAL_INT_FATAL) {81AH_PRIVATE(ah)->ah_fatalState[0] = isr;82AH_PRIVATE(ah)->ah_fatalState[1] = OS_REG_READ(ah, AR_ISR_S0_S);83AH_PRIVATE(ah)->ah_fatalState[2] = OS_REG_READ(ah, AR_ISR_S1_S);84AH_PRIVATE(ah)->ah_fatalState[3] = OS_REG_READ(ah, AR_ISR_S2_S);85AH_PRIVATE(ah)->ah_fatalState[4] = OS_REG_READ(ah, AR_ISR_S3_S);86AH_PRIVATE(ah)->ah_fatalState[5] = OS_REG_READ(ah, AR_ISR_S4_S);87HALDEBUG(ah, HAL_DEBUG_ANY,88"%s: fatal error, ISR_RAC=0x%x ISR_S2_S=0x%x\n",89__func__, isr, AH_PRIVATE(ah)->ah_fatalState[3]);90}91return AH_TRUE;92}9394HAL_INT95ar5211GetInterrupts(struct ath_hal *ah)96{97return AH5211(ah)->ah_maskReg;98}99100/*101* Atomically enables NIC interrupts. Interrupts are passed in102* via the enumerated bitmask in ints.103*/104HAL_INT105ar5211SetInterrupts(struct ath_hal *ah, HAL_INT ints)106{107struct ath_hal_5211 *ahp = AH5211(ah);108uint32_t omask = ahp->ah_maskReg;109uint32_t mask;110111HALDEBUG(ah, HAL_DEBUG_INTERRUPT, "%s: 0x%x => 0x%x\n",112__func__, omask, ints);113114/*115* Disable interrupts here before reading & modifying116* the mask so that the ISR does not modify the mask117* out from under us.118*/119if (omask & HAL_INT_GLOBAL) {120HALDEBUG(ah, HAL_DEBUG_INTERRUPT, "%s: disable IER\n", __func__);121OS_REG_WRITE(ah, AR_IER, AR_IER_DISABLE);122/* XXX??? */123(void) OS_REG_READ(ah, AR_IER); /* flush write to HW */124}125126mask = ints & HAL_INT_COMMON;127if (ints & HAL_INT_TX) {128if (ahp->ah_txOkInterruptMask)129mask |= AR_IMR_TXOK;130if (ahp->ah_txErrInterruptMask)131mask |= AR_IMR_TXERR;132if (ahp->ah_txDescInterruptMask)133mask |= AR_IMR_TXDESC;134if (ahp->ah_txEolInterruptMask)135mask |= AR_IMR_TXEOL;136}137if (ints & HAL_INT_RX)138mask |= AR_IMR_RXOK | AR_IMR_RXERR | AR_IMR_RXDESC;139if (ints & HAL_INT_FATAL) {140/*141* NB: ar5212Reset sets MCABT+SSERR+DPERR in AR_IMR_S2142* so enabling HIUERR enables delivery.143*/144mask |= AR_IMR_HIUERR;145}146147/* Write the new IMR and store off our SW copy. */148HALDEBUG(ah, HAL_DEBUG_INTERRUPT, "%s: new IMR 0x%x\n", __func__, mask);149OS_REG_WRITE(ah, AR_IMR, mask);150ahp->ah_maskReg = ints;151152/* Re-enable interrupts as appropriate. */153if (ints & HAL_INT_GLOBAL) {154HALDEBUG(ah, HAL_DEBUG_INTERRUPT, "%s: enable IER\n", __func__);155OS_REG_WRITE(ah, AR_IER, AR_IER_ENABLE);156}157158return omask;159}160161162