Path: blob/main/sys/dev/ath/ath_hal/ar5210/ar5210_interrupts.c
39566 views
/*-1* SPDX-License-Identifier: ISC2*3* Copyright (c) 2002-2008 Sam Leffler, Errno Consulting4* Copyright (c) 2002-2004 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 "ar5210/ar5210.h"24#include "ar5210/ar5210reg.h"2526/*27* Return non-zero if an interrupt is pending.28*/29HAL_BOOL30ar5210IsInterruptPending(struct ath_hal *ah)31{32return (OS_REG_READ(ah, AR_INTPEND) ? AH_TRUE : AH_FALSE);33}3435/*36* Read the Interrupt Status Register value and return37* an abstracted bitmask of the data found in the ISR.38* Note that reading the ISR clear pending interrupts.39*/40HAL_BOOL41ar5210GetPendingInterrupts(struct ath_hal *ah, HAL_INT *masked)42{43#define AR_FATAL_INT \44(AR_ISR_MCABT_INT | AR_ISR_SSERR_INT | AR_ISR_DPERR_INT | AR_ISR_RXORN_INT)45struct ath_hal_5210 *ahp = AH5210(ah);46uint32_t isr;4748isr = OS_REG_READ(ah, AR_ISR);49if (isr == 0xffffffff) {50*masked = 0;51return AH_FALSE;52}5354/*55* Mask interrupts that have no device-independent56* representation; these are added back below. We57* also masked with the abstracted IMR to insure no58* status bits leak through that weren't requested59* (e.g. RXNOFRM) and that might confuse the caller.60*/61*masked = (isr & (HAL_INT_COMMON - HAL_INT_BNR)) & ahp->ah_maskReg;6263if (isr & AR_FATAL_INT)64*masked |= HAL_INT_FATAL;65if (isr & (AR_ISR_RXOK_INT | AR_ISR_RXERR_INT))66*masked |= HAL_INT_RX;67if (isr & (AR_ISR_TXOK_INT | AR_ISR_TXDESC_INT | AR_ISR_TXERR_INT | AR_ISR_TXEOL_INT))68*masked |= HAL_INT_TX;6970/*71* On fatal errors collect ISR state for debugging.72*/73if (*masked & HAL_INT_FATAL) {74AH_PRIVATE(ah)->ah_fatalState[0] = isr;75}7677return AH_TRUE;78#undef AR_FATAL_INT79}8081HAL_INT82ar5210GetInterrupts(struct ath_hal *ah)83{84return AH5210(ah)->ah_maskReg;85}8687HAL_INT88ar5210SetInterrupts(struct ath_hal *ah, HAL_INT ints)89{90struct ath_hal_5210 *ahp = AH5210(ah);91uint32_t omask = ahp->ah_maskReg;92uint32_t mask;9394HALDEBUG(ah, HAL_DEBUG_INTERRUPT, "%s: 0x%x => 0x%x\n",95__func__, omask, ints);9697/*98* Disable interrupts here before reading & modifying99* the mask so that the ISR does not modify the mask100* out from under us.101*/102if (omask & HAL_INT_GLOBAL) {103HALDEBUG(ah, HAL_DEBUG_INTERRUPT, "%s: disable IER\n", __func__);104OS_REG_WRITE(ah, AR_IER, AR_IER_DISABLE);105}106107mask = ints & (HAL_INT_COMMON - HAL_INT_BNR);108if (ints & HAL_INT_RX)109mask |= AR_IMR_RXOK_INT | AR_IMR_RXERR_INT;110if (ints & HAL_INT_TX) {111if (ahp->ah_txOkInterruptMask)112mask |= AR_IMR_TXOK_INT;113if (ahp->ah_txErrInterruptMask)114mask |= AR_IMR_TXERR_INT;115if (ahp->ah_txDescInterruptMask)116mask |= AR_IMR_TXDESC_INT;117if (ahp->ah_txEolInterruptMask)118mask |= AR_IMR_TXEOL_INT;119}120121/* Write the new IMR and store off our SW copy. */122HALDEBUG(ah, HAL_DEBUG_INTERRUPT, "%s: new IMR 0x%x\n", __func__, mask);123OS_REG_WRITE(ah, AR_IMR, mask);124ahp->ah_maskReg = ints;125126/* Re-enable interrupts as appropriate. */127if (ints & HAL_INT_GLOBAL) {128HALDEBUG(ah, HAL_DEBUG_INTERRUPT, "%s: enable IER\n", __func__);129OS_REG_WRITE(ah, AR_IER, AR_IER_ENABLE);130}131132return omask;133}134135136