Path: blob/main/sys/dev/ath/ath_hal/ar5416/ar5416_misc.c
39566 views
/*-1* SPDX-License-Identifier: ISC2*3* Copyright (c) 2002-2008 Sam Leffler, Errno Consulting4* Copyright (c) 2002-2008 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"22#include "ah_devid.h"23#include "ah_desc.h" /* NB: for HAL_PHYERR* */2425#include "ar5416/ar5416.h"26#include "ar5416/ar5416reg.h"27#include "ar5416/ar5416phy.h"2829#include "ah_eeprom_v14.h" /* for owl_get_ntxchains() */3031/*32* Return the wireless modes (a,b,g,n,t) supported by hardware.33*34* This value is what is actually supported by the hardware35* and is unaffected by regulatory/country code settings.36*37*/38u_int39ar5416GetWirelessModes(struct ath_hal *ah)40{41u_int mode;42struct ath_hal_private *ahpriv = AH_PRIVATE(ah);43HAL_CAPABILITIES *pCap = &ahpriv->ah_caps;4445mode = ar5212GetWirelessModes(ah);4647/* Only enable HT modes if the NIC supports HT */48if (pCap->halHTSupport == AH_TRUE && (mode & HAL_MODE_11A))49mode |= HAL_MODE_11NA_HT2050| HAL_MODE_11NA_HT40PLUS51| HAL_MODE_11NA_HT40MINUS52;53if (pCap->halHTSupport == AH_TRUE && (mode & HAL_MODE_11G))54mode |= HAL_MODE_11NG_HT2055| HAL_MODE_11NG_HT40PLUS56| HAL_MODE_11NG_HT40MINUS57;58return mode;59}6061/*62* Change the LED blinking pattern to correspond to the connectivity63*/64void65ar5416SetLedState(struct ath_hal *ah, HAL_LED_STATE state)66{67static const uint32_t ledbits[8] = {68AR_MAC_LED_ASSOC_NONE, /* HAL_LED_INIT */69AR_MAC_LED_ASSOC_PEND, /* HAL_LED_SCAN */70AR_MAC_LED_ASSOC_PEND, /* HAL_LED_AUTH */71AR_MAC_LED_ASSOC_ACTIVE, /* HAL_LED_ASSOC*/72AR_MAC_LED_ASSOC_ACTIVE, /* HAL_LED_RUN */73AR_MAC_LED_ASSOC_NONE,74AR_MAC_LED_ASSOC_NONE,75AR_MAC_LED_ASSOC_NONE,76};7778if (AR_SREV_HOWL(ah))79return;8081/*82* Set the blink operating mode.83*/84OS_REG_RMW_FIELD(ah, AR_MAC_LED,85AR_MAC_LED_ASSOC, ledbits[state & 0x7]);8687/* XXX Blink slow mode? */88/* XXX Blink threshold? */89/* XXX Blink sleep hystersis? */9091/*92* Set the LED blink configuration to be proportional93* to the current TX and RX filter bytes. (Ie, RX'ed94* frames that don't match the filter are ignored.)95* This means that higher TX/RX throughput will result96* in the blink rate increasing.97*/98OS_REG_RMW_FIELD(ah, AR_MAC_LED, AR_MAC_LED_MODE,99AR_MAC_LED_MODE_PROP);100}101102/*103* Get the current hardware tsf for stamlme104*/105uint64_t106ar5416GetTsf64(struct ath_hal *ah)107{108uint32_t low1, low2, u32;109110/* sync multi-word read */111low1 = OS_REG_READ(ah, AR_TSF_L32);112u32 = OS_REG_READ(ah, AR_TSF_U32);113low2 = OS_REG_READ(ah, AR_TSF_L32);114if (low2 < low1) { /* roll over */115/*116* If we are not preempted this will work. If we are117* then we re-reading AR_TSF_U32 does no good as the118* low bits will be meaningless. Likewise reading119* L32, U32, U32, then comparing the last two reads120* to check for rollover doesn't help if preempted--so121* we take this approach as it costs one less PCI read122* which can be noticeable when doing things like123* timestamping packets in monitor mode.124*/125u32++;126}127return (((uint64_t) u32) << 32) | ((uint64_t) low2);128}129130/*131* Update the TSF.132*133* The full TSF is only updated once the upper 32 bits have134* been written. Writing only the lower 32 bits of the TSF135* will not actually correctly update the TSF.136*137* The #if 0'ed code is to check whether the previous TSF138* reset or write has completed before writing to the139* TSF. Strictly speaking, it should be also checked before140* reading the TSF as the write/reset may not have completed.141*/142void143ar5416SetTsf64(struct ath_hal *ah, uint64_t tsf64)144{145/* XXX check if this is correct! */146#if 0147int i;148uint32_t v;149150for (i = 0; i < 10; i++) {151v = OS_REG_READ(ah, AR_SLP32_MODE);152if ((v & AR_SLP32_TSF_WRITE_STATUS) == 0)153break;154OS_DELAY(10);155}156if (i == 10)157ath_hal_printf(ah, "%s: couldn't slew things right!\n", __func__);158#endif159160OS_REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);161OS_REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);162}163164/*165* Reset the current hardware tsf for stamlme.166*/167void168ar5416ResetTsf(struct ath_hal *ah)169{170uint32_t v;171int i;172173for (i = 0; i < 10; i++) {174v = OS_REG_READ(ah, AR_SLP32_MODE);175if ((v & AR_SLP32_TSF_WRITE_STATUS) == 0)176break;177OS_DELAY(10);178}179OS_REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);180}181182uint32_t183ar5416GetCurRssi(struct ath_hal *ah)184{185if (AR_SREV_OWL(ah))186return (OS_REG_READ(ah, AR_PHY_CURRENT_RSSI) & 0xff);187return (OS_REG_READ(ah, AR9130_PHY_CURRENT_RSSI) & 0xff);188}189190HAL_BOOL191ar5416SetAntennaSwitch(struct ath_hal *ah, HAL_ANT_SETTING settings)192{193return AH_TRUE;194}195196/* Setup decompression for given key index */197HAL_BOOL198ar5416SetDecompMask(struct ath_hal *ah, uint16_t keyidx, int en)199{200return AH_TRUE;201}202203/* Setup coverage class */204void205ar5416SetCoverageClass(struct ath_hal *ah, uint8_t coverageclass, int now)206{207208ar5212SetCoverageClass(ah, coverageclass, now);209}210211/*212* Return the busy for rx_frame, rx_clear, and tx_frame213*/214HAL_BOOL215ar5416GetMibCycleCounts(struct ath_hal *ah, HAL_SURVEY_SAMPLE *hsample)216{217struct ath_hal_5416 *ahp = AH5416(ah);218u_int32_t good = AH_TRUE;219220/* XXX freeze/unfreeze mib counters */221uint32_t rc = OS_REG_READ(ah, AR_RCCNT);222uint32_t ec = OS_REG_READ(ah, AR_EXTRCCNT);223uint32_t rf = OS_REG_READ(ah, AR_RFCNT);224uint32_t tf = OS_REG_READ(ah, AR_TFCNT);225uint32_t cc = OS_REG_READ(ah, AR_CCCNT); /* read cycles last */226227if (ahp->ah_cycleCount == 0 || ahp->ah_cycleCount > cc) {228/*229* Cycle counter wrap (or initial call); it's not possible230* to accurately calculate a value because the registers231* right shift rather than wrap--so punt and return 0.232*/233HALDEBUG(ah, HAL_DEBUG_ANY,234"%s: cycle counter wrap. ExtBusy = 0\n", __func__);235good = AH_FALSE;236} else {237hsample->cycle_count = cc - ahp->ah_cycleCount;238hsample->chan_busy = rc - ahp->ah_ctlBusy;239hsample->ext_chan_busy = ec - ahp->ah_extBusy;240hsample->rx_busy = rf - ahp->ah_rxBusy;241hsample->tx_busy = tf - ahp->ah_txBusy;242}243244/*245* Keep a copy of the MIB results so the next sample has something246* to work from.247*/248ahp->ah_cycleCount = cc;249ahp->ah_rxBusy = rf;250ahp->ah_ctlBusy = rc;251ahp->ah_txBusy = tf;252ahp->ah_extBusy = ec;253254return (good);255}256257/*258* Setup the TX/RX chainmasks - this needs to be done before a call259* to the reset method as it doesn't update the hardware.260*/261void262ar5416SetChainMasks(struct ath_hal *ah, uint32_t tx_chainmask,263uint32_t rx_chainmask)264{265HAL_CAPABILITIES *pCap = &AH_PRIVATE(ah)->ah_caps;266267AH5416(ah)->ah_tx_chainmask = tx_chainmask & pCap->halTxChainMask;268AH5416(ah)->ah_rx_chainmask = rx_chainmask & pCap->halRxChainMask;269}270271/*272* Return approximation of extension channel busy over an time interval273* 0% (clear) -> 100% (busy)274*275* XXX TODO: update this to correctly sample all the counters,276* rather than a subset of it.277*/278uint32_t279ar5416Get11nExtBusy(struct ath_hal *ah)280{281struct ath_hal_5416 *ahp = AH5416(ah);282uint32_t busy; /* percentage */283uint32_t cycleCount, ctlBusy, extBusy;284285ctlBusy = OS_REG_READ(ah, AR_RCCNT);286extBusy = OS_REG_READ(ah, AR_EXTRCCNT);287cycleCount = OS_REG_READ(ah, AR_CCCNT);288289if (ahp->ah_cycleCount == 0 || ahp->ah_cycleCount > cycleCount) {290/*291* Cycle counter wrap (or initial call); it's not possible292* to accurately calculate a value because the registers293* right shift rather than wrap--so punt and return 0.294*/295busy = 0;296HALDEBUG(ah, HAL_DEBUG_ANY, "%s: cycle counter wrap. ExtBusy = 0\n",297__func__);298299} else {300uint32_t cycleDelta = cycleCount - ahp->ah_cycleCount;301uint32_t ctlBusyDelta = ctlBusy - ahp->ah_ctlBusy;302uint32_t extBusyDelta = extBusy - ahp->ah_extBusy;303uint32_t ctlClearDelta = 0;304305/* Compute control channel rxclear.306* The cycle delta may be less than the control channel delta.307* This could be solved by freezing the timers (or an atomic read,308* if one was available). Checking for the condition should be309* sufficient.310*/311if (cycleDelta > ctlBusyDelta) {312ctlClearDelta = cycleDelta - ctlBusyDelta;313}314315/* Compute ratio of extension channel busy to control channel clear316* as an approximation to extension channel cleanliness.317*318* According to the hardware folks, ext rxclear is undefined319* if the ctrl rxclear is de-asserted (i.e. busy)320*/321if (ctlClearDelta) {322busy = (extBusyDelta * 100) / ctlClearDelta;323} else {324busy = 100;325}326if (busy > 100) {327busy = 100;328}329#if 0330HALDEBUG(ah, HAL_DEBUG_ANY, "%s: cycleDelta 0x%x, ctlBusyDelta 0x%x, "331"extBusyDelta 0x%x, ctlClearDelta 0x%x, "332"busy %d\n",333__func__, cycleDelta, ctlBusyDelta, extBusyDelta, ctlClearDelta, busy);334#endif335}336337ahp->ah_cycleCount = cycleCount;338ahp->ah_ctlBusy = ctlBusy;339ahp->ah_extBusy = extBusy;340341return busy;342}343344/*345* Configure 20/40 operation346*347* 20/40 = joint rx clear (control and extension)348* 20 = rx clear (control)349*350* - NOTE: must stop MAC (tx) and requeue 40 MHz packets as 20 MHz when changing351* from 20/40 => 20 only352*/353void354ar5416Set11nMac2040(struct ath_hal *ah, HAL_HT_MACMODE mode)355{356uint32_t macmode;357358/* Configure MAC for 20/40 operation */359if (mode == HAL_HT_MACMODE_2040) {360macmode = AR_2040_JOINED_RX_CLEAR;361} else {362macmode = 0;363}364OS_REG_WRITE(ah, AR_2040_MODE, macmode);365}366367/*368* Get Rx clear (control/extension channel)369*370* Returns active low (busy) for ctrl/ext channel371* Owl 2.0372*/373HAL_HT_RXCLEAR374ar5416Get11nRxClear(struct ath_hal *ah)375{376HAL_HT_RXCLEAR rxclear = 0;377uint32_t val;378379val = OS_REG_READ(ah, AR_DIAG_SW);380381/* control channel */382if (val & AR_DIAG_RXCLEAR_CTL_LOW) {383rxclear |= HAL_RX_CLEAR_CTL_LOW;384}385/* extension channel */386if (val & AR_DIAG_RXCLEAR_EXT_LOW) {387rxclear |= HAL_RX_CLEAR_EXT_LOW;388}389return rxclear;390}391392/*393* Set Rx clear (control/extension channel)394*395* Useful for forcing the channel to appear busy for396* debugging/diagnostics397* Owl 2.0398*/399void400ar5416Set11nRxClear(struct ath_hal *ah, HAL_HT_RXCLEAR rxclear)401{402/* control channel */403if (rxclear & HAL_RX_CLEAR_CTL_LOW) {404OS_REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RXCLEAR_CTL_LOW);405} else {406OS_REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_RXCLEAR_CTL_LOW);407}408/* extension channel */409if (rxclear & HAL_RX_CLEAR_EXT_LOW) {410OS_REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RXCLEAR_EXT_LOW);411} else {412OS_REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_RXCLEAR_EXT_LOW);413}414}415416/* XXX shouldn't be here! */417#define TU_TO_USEC(_tu) ((_tu) << 10)418419HAL_STATUS420ar5416SetQuiet(struct ath_hal *ah, uint32_t period, uint32_t duration,421uint32_t nextStart, HAL_QUIET_FLAG flag)422{423uint32_t period_us = TU_TO_USEC(period); /* convert to us unit */424uint32_t nextStart_us = TU_TO_USEC(nextStart); /* convert to us unit */425if (flag & HAL_QUIET_ENABLE) {426if ((!nextStart) || (flag & HAL_QUIET_ADD_CURRENT_TSF)) {427/* Add the nextStart offset to the current TSF */428nextStart_us += OS_REG_READ(ah, AR_TSF_L32);429}430if (flag & HAL_QUIET_ADD_SWBA_RESP_TIME) {431nextStart_us += ah->ah_config.ah_sw_beacon_response_time;432}433OS_REG_RMW_FIELD(ah, AR_QUIET1, AR_QUIET1_QUIET_ACK_CTS_ENABLE, 1);434OS_REG_WRITE(ah, AR_QUIET2, SM(duration, AR_QUIET2_QUIET_DUR));435OS_REG_WRITE(ah, AR_QUIET_PERIOD, period_us);436OS_REG_WRITE(ah, AR_NEXT_QUIET, nextStart_us);437OS_REG_SET_BIT(ah, AR_TIMER_MODE, AR_TIMER_MODE_QUIET);438} else {439OS_REG_CLR_BIT(ah, AR_TIMER_MODE, AR_TIMER_MODE_QUIET);440}441return HAL_OK;442}443#undef TU_TO_USEC444445HAL_STATUS446ar5416GetCapability(struct ath_hal *ah, HAL_CAPABILITY_TYPE type,447uint32_t capability, uint32_t *result)448{449switch (type) {450case HAL_CAP_BB_HANG:451switch (capability) {452case HAL_BB_HANG_RIFS:453return (AR_SREV_HOWL(ah) || AR_SREV_SOWL(ah)) ? HAL_OK : HAL_ENOTSUPP;454case HAL_BB_HANG_DFS:455return (AR_SREV_HOWL(ah) || AR_SREV_SOWL(ah)) ? HAL_OK : HAL_ENOTSUPP;456case HAL_BB_HANG_RX_CLEAR:457return AR_SREV_MERLIN(ah) ? HAL_OK : HAL_ENOTSUPP;458}459break;460case HAL_CAP_MAC_HANG:461return ((ah->ah_macVersion == AR_XSREV_VERSION_OWL_PCI) ||462(ah->ah_macVersion == AR_XSREV_VERSION_OWL_PCIE) ||463AR_SREV_HOWL(ah) || AR_SREV_SOWL(ah)) ?464HAL_OK : HAL_ENOTSUPP;465case HAL_CAP_DIVERSITY: /* disable classic fast diversity */466return HAL_ENXIO;467case HAL_CAP_ENFORCE_TXOP:468if (capability == 0)469return (HAL_OK);470if (capability != 1)471return (HAL_ENOTSUPP);472(*result) =473!! (AH5212(ah)->ah_miscMode & AR_PCU_TXOP_TBTT_LIMIT_ENA);474return (HAL_OK);475default:476break;477}478return ar5212GetCapability(ah, type, capability, result);479}480481HAL_BOOL482ar5416SetCapability(struct ath_hal *ah, HAL_CAPABILITY_TYPE type,483u_int32_t capability, u_int32_t setting, HAL_STATUS *status)484{485HAL_CAPABILITIES *pCap = &AH_PRIVATE(ah)->ah_caps;486487switch (type) {488case HAL_CAP_RX_CHAINMASK:489setting &= ath_hal_eepromGet(ah, AR_EEP_RXMASK, NULL);490pCap->halRxChainMask = setting;491if (owl_get_ntxchains(setting) > 2)492pCap->halRxStreams = 2;493else494pCap->halRxStreams = 1;495return AH_TRUE;496case HAL_CAP_TX_CHAINMASK:497setting &= ath_hal_eepromGet(ah, AR_EEP_TXMASK, NULL);498pCap->halTxChainMask = setting;499if (owl_get_ntxchains(setting) > 2)500pCap->halTxStreams = 2;501else502pCap->halTxStreams = 1;503return AH_TRUE;504case HAL_CAP_ENFORCE_TXOP:505if (capability != 1)506return AH_FALSE;507if (setting) {508AH5212(ah)->ah_miscMode509|= AR_PCU_TXOP_TBTT_LIMIT_ENA;510OS_REG_SET_BIT(ah, AR_MISC_MODE,511AR_PCU_TXOP_TBTT_LIMIT_ENA);512} else {513AH5212(ah)->ah_miscMode514&= ~AR_PCU_TXOP_TBTT_LIMIT_ENA;515OS_REG_CLR_BIT(ah, AR_MISC_MODE,516AR_PCU_TXOP_TBTT_LIMIT_ENA);517}518return AH_TRUE;519default:520break;521}522return ar5212SetCapability(ah, type, capability, setting, status);523}524525static int ar5416DetectMacHang(struct ath_hal *ah);526static int ar5416DetectBBHang(struct ath_hal *ah);527528HAL_BOOL529ar5416GetDiagState(struct ath_hal *ah, int request,530const void *args, uint32_t argsize,531void **result, uint32_t *resultsize)532{533struct ath_hal_5416 *ahp = AH5416(ah);534int hangs;535536if (ath_hal_getdiagstate(ah, request, args, argsize, result, resultsize))537return AH_TRUE;538switch (request) {539case HAL_DIAG_EEPROM:540return ath_hal_eepromDiag(ah, request,541args, argsize, result, resultsize);542case HAL_DIAG_CHECK_HANGS:543if (argsize != sizeof(int))544return AH_FALSE;545hangs = *(const int *) args;546ahp->ah_hangs = 0;547if (hangs & HAL_BB_HANGS)548ahp->ah_hangs |= ar5416DetectBBHang(ah);549/* NB: if BB is hung MAC will be hung too so skip check */550if (ahp->ah_hangs == 0 && (hangs & HAL_MAC_HANGS))551ahp->ah_hangs |= ar5416DetectMacHang(ah);552*result = &ahp->ah_hangs;553*resultsize = sizeof(ahp->ah_hangs);554return AH_TRUE;555}556return ar5212GetDiagState(ah, request,557args, argsize, result, resultsize);558}559560HAL_BOOL561ar5416SetRifsDelay(struct ath_hal *ah, const struct ieee80211_channel *chan,562HAL_BOOL enable)563{564uint32_t val;565HAL_BOOL is_chan_2g = AH_FALSE;566HAL_BOOL is_ht40 = AH_FALSE;567568if (chan)569is_chan_2g = IEEE80211_IS_CHAN_2GHZ(chan);570571if (chan)572is_ht40 = IEEE80211_IS_CHAN_HT40(chan);573574/* Only support disabling RIFS delay for now */575HALASSERT(enable == AH_FALSE);576577if (enable == AH_TRUE)578return AH_FALSE;579580/* Change RIFS init delay to 0 */581val = OS_REG_READ(ah, AR_PHY_HEAVY_CLIP_FACTOR_RIFS);582val &= ~AR_PHY_RIFS_INIT_DELAY;583OS_REG_WRITE(ah, AR_PHY_HEAVY_CLIP_FACTOR_RIFS, val);584585/*586* For Owl, RIFS RX parameters are controlled differently;587* it isn't enabled in the inivals by default.588*589* For Sowl/Howl, RIFS RX is enabled in the inivals by default;590* the following code sets them back to non-RIFS values.591*592* For > Sowl/Howl, RIFS RX can be left on by default and so593* this function shouldn't be called.594*/595if ((! AR_SREV_SOWL(ah)) && (! AR_SREV_HOWL(ah)))596return AH_TRUE;597598/* Reset search delay to default values */599if (is_chan_2g)600if (is_ht40)601OS_REG_WRITE(ah, AR_PHY_SEARCH_START_DELAY, 0x268);602else603OS_REG_WRITE(ah, AR_PHY_SEARCH_START_DELAY, 0x134);604else605if (is_ht40)606OS_REG_WRITE(ah, AR_PHY_SEARCH_START_DELAY, 0x370);607else608OS_REG_WRITE(ah, AR_PHY_SEARCH_START_DELAY, 0x1b8);609610return AH_TRUE;611}612613static HAL_BOOL614ar5416CompareDbgHang(struct ath_hal *ah, const mac_dbg_regs_t *regs,615const hal_mac_hang_check_t *check)616{617int found_states;618619found_states = 0;620if (check->states & dcu_chain_state) {621int i;622623for (i = 0; i < 6; i++) {624if (((regs->dma_dbg_4 >> (5*i)) & 0x1f) ==625check->dcu_chain_state)626found_states |= dcu_chain_state;627}628for (i = 0; i < 4; i++) {629if (((regs->dma_dbg_5 >> (5*i)) & 0x1f) ==630check->dcu_chain_state)631found_states |= dcu_chain_state;632}633}634if (check->states & dcu_complete_state) {635if ((regs->dma_dbg_6 & 0x3) == check->dcu_complete_state)636found_states |= dcu_complete_state;637}638if (check->states & qcu_stitch_state) {639if (((regs->dma_dbg_3 >> 18) & 0xf) == check->qcu_stitch_state)640found_states |= qcu_stitch_state;641}642if (check->states & qcu_fetch_state) {643if (((regs->dma_dbg_3 >> 22) & 0xf) == check->qcu_fetch_state)644found_states |= qcu_fetch_state;645}646if (check->states & qcu_complete_state) {647if (((regs->dma_dbg_3 >> 26) & 0x7) == check->qcu_complete_state)648found_states |= qcu_complete_state;649}650return (found_states == check->states);651}652653#define NUM_STATUS_READS 50654655static int656ar5416DetectMacHang(struct ath_hal *ah)657{658static const hal_mac_hang_check_t hang_sig1 = {659.dcu_chain_state = 0x6,660.dcu_complete_state = 0x1,661.states = dcu_chain_state662| dcu_complete_state,663};664static const hal_mac_hang_check_t hang_sig2 = {665.qcu_stitch_state = 0x9,666.qcu_fetch_state = 0x8,667.qcu_complete_state = 0x4,668.states = qcu_stitch_state669| qcu_fetch_state670| qcu_complete_state,671};672mac_dbg_regs_t mac_dbg;673int i;674675mac_dbg.dma_dbg_3 = OS_REG_READ(ah, AR_DMADBG_3);676mac_dbg.dma_dbg_4 = OS_REG_READ(ah, AR_DMADBG_4);677mac_dbg.dma_dbg_5 = OS_REG_READ(ah, AR_DMADBG_5);678mac_dbg.dma_dbg_6 = OS_REG_READ(ah, AR_DMADBG_6);679for (i = 1; i <= NUM_STATUS_READS; i++) {680if (mac_dbg.dma_dbg_3 != OS_REG_READ(ah, AR_DMADBG_3) ||681mac_dbg.dma_dbg_4 != OS_REG_READ(ah, AR_DMADBG_4) ||682mac_dbg.dma_dbg_5 != OS_REG_READ(ah, AR_DMADBG_5) ||683mac_dbg.dma_dbg_6 != OS_REG_READ(ah, AR_DMADBG_6))684return 0;685}686687if (ar5416CompareDbgHang(ah, &mac_dbg, &hang_sig1))688return HAL_MAC_HANG_SIG1;689if (ar5416CompareDbgHang(ah, &mac_dbg, &hang_sig2))690return HAL_MAC_HANG_SIG2;691692HALDEBUG(ah, HAL_DEBUG_HANG, "%s Found an unknown MAC hang signature "693"DMADBG_3=0x%x DMADBG_4=0x%x DMADBG_5=0x%x DMADBG_6=0x%x\n",694__func__, mac_dbg.dma_dbg_3, mac_dbg.dma_dbg_4, mac_dbg.dma_dbg_5,695mac_dbg.dma_dbg_6);696697return 0;698}699700/*701* Determine if the baseband using the Observation Bus Register702*/703static int704ar5416DetectBBHang(struct ath_hal *ah)705{706#define N(a) (sizeof(a)/sizeof(a[0]))707/*708* Check the PCU Observation Bus 1 register (0x806c)709* NUM_STATUS_READS times710*711* 4 known BB hang signatures -712* [1] bits 8,9,11 are 0. State machine state (bits 25-31) is 0x1E713* [2] bits 8,9 are 1, bit 11 is 0. State machine state714* (bits 25-31) is 0x52715* [3] bits 8,9 are 1, bit 11 is 0. State machine state716* (bits 25-31) is 0x18717* [4] bit 10 is 1, bit 11 is 0. WEP state (bits 12-17) is 0x2,718* Rx State (bits 20-24) is 0x7.719*/720static const struct {721uint32_t val;722uint32_t mask;723int code;724} hang_list[] = {725/* Reg Value Reg Mask Hang Code XXX */726{ 0x1E000000, 0x7E000B00, HAL_BB_HANG_DFS },727{ 0x52000B00, 0x7E000B00, HAL_BB_HANG_RIFS },728{ 0x18000B00, 0x7E000B00, HAL_BB_HANG_RX_CLEAR },729{ 0x00702400, 0x7E7FFFEF, HAL_BB_HANG_RX_CLEAR }730};731uint32_t hang_sig;732int i;733734hang_sig = OS_REG_READ(ah, AR_OBSERV_1);735for (i = 1; i <= NUM_STATUS_READS; i++) {736if (hang_sig != OS_REG_READ(ah, AR_OBSERV_1))737return 0;738}739for (i = 0; i < N(hang_list); i++)740if ((hang_sig & hang_list[i].mask) == hang_list[i].val) {741HALDEBUG(ah, HAL_DEBUG_HANG,742"%s BB hang, signature 0x%x, code 0x%x\n",743__func__, hang_sig, hang_list[i].code);744return hang_list[i].code;745}746747HALDEBUG(ah, HAL_DEBUG_HANG, "%s Found an unknown BB hang signature! "748"<0x806c>=0x%x\n", __func__, hang_sig);749750return 0;751#undef N752}753#undef NUM_STATUS_READS754755756