Path: blob/main/sys/dev/ath/ath_hal/ar5212/ar5212_recv.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_desc.h"2324#include "ar5212/ar5212.h"25#include "ar5212/ar5212reg.h"26#include "ar5212/ar5212desc.h"2728/*29* Get the RXDP.30*/31uint32_t32ar5212GetRxDP(struct ath_hal *ath, HAL_RX_QUEUE qtype)33{3435HALASSERT(qtype == HAL_RX_QUEUE_HP);36return OS_REG_READ(ath, AR_RXDP);37}3839/*40* Set the RxDP.41*/42void43ar5212SetRxDP(struct ath_hal *ah, uint32_t rxdp, HAL_RX_QUEUE qtype)44{4546HALASSERT(qtype == HAL_RX_QUEUE_HP);47OS_REG_WRITE(ah, AR_RXDP, rxdp);48HALASSERT(OS_REG_READ(ah, AR_RXDP) == rxdp);49}5051/*52* Set Receive Enable bits.53*/54void55ar5212EnableReceive(struct ath_hal *ah)56{57OS_REG_WRITE(ah, AR_CR, AR_CR_RXE);58}5960/*61* Stop Receive at the DMA engine62*/63HAL_BOOL64ar5212StopDmaReceive(struct ath_hal *ah)65{66OS_MARK(ah, AH_MARK_RX_CTL, AH_MARK_RX_CTL_DMA_STOP);67OS_REG_WRITE(ah, AR_CR, AR_CR_RXD); /* Set receive disable bit */68if (!ath_hal_wait(ah, AR_CR, AR_CR_RXE, 0)) {69OS_MARK(ah, AH_MARK_RX_CTL, AH_MARK_RX_CTL_DMA_STOP_ERR);70#ifdef AH_DEBUG71ath_hal_printf(ah, "%s: dma failed to stop in 10ms\n"72"AR_CR=0x%08x\nAR_DIAG_SW=0x%08x\n",73__func__,74OS_REG_READ(ah, AR_CR),75OS_REG_READ(ah, AR_DIAG_SW));76#endif77return AH_FALSE;78} else {79return AH_TRUE;80}81}8283/*84* Start Transmit at the PCU engine (unpause receive)85*/86void87ar5212StartPcuReceive(struct ath_hal *ah, HAL_BOOL is_scanning)88{89struct ath_hal_private *ahp = AH_PRIVATE(ah);9091OS_MARK(ah, AH_MARK_RX_CTL, AH_MARK_RX_CTL_PCU_START);92OS_REG_WRITE(ah, AR_DIAG_SW,93OS_REG_READ(ah, AR_DIAG_SW) &~ AR_DIAG_RX_DIS);94ar5212EnableMibCounters(ah);95/* NB: restore current settings if we're not scanning */96ar5212AniReset(ah, ahp->ah_curchan, ahp->ah_opmode, !is_scanning);97}9899/*100* Stop Transmit at the PCU engine (pause receive)101*/102void103ar5212StopPcuReceive(struct ath_hal *ah)104{105OS_MARK(ah, AH_MARK_RX_CTL, AH_MARK_RX_CTL_PCU_STOP);106OS_REG_WRITE(ah, AR_DIAG_SW,107OS_REG_READ(ah, AR_DIAG_SW) | AR_DIAG_RX_DIS);108ar5212DisableMibCounters(ah);109}110111/*112* Set multicast filter 0 (lower 32-bits)113* filter 1 (upper 32-bits)114*/115void116ar5212SetMulticastFilter(struct ath_hal *ah, uint32_t filter0, uint32_t filter1)117{118OS_REG_WRITE(ah, AR_MCAST_FIL0, filter0);119OS_REG_WRITE(ah, AR_MCAST_FIL1, filter1);120}121122/*123* Clear multicast filter by index124*/125HAL_BOOL126ar5212ClrMulticastFilterIndex(struct ath_hal *ah, uint32_t ix)127{128uint32_t val;129130if (ix >= 64)131return AH_FALSE;132if (ix >= 32) {133val = OS_REG_READ(ah, AR_MCAST_FIL1);134OS_REG_WRITE(ah, AR_MCAST_FIL1, (val &~ (1<<(ix-32))));135} else {136val = OS_REG_READ(ah, AR_MCAST_FIL0);137OS_REG_WRITE(ah, AR_MCAST_FIL0, (val &~ (1<<ix)));138}139return AH_TRUE;140}141142/*143* Set multicast filter by index144*/145HAL_BOOL146ar5212SetMulticastFilterIndex(struct ath_hal *ah, uint32_t ix)147{148uint32_t val;149150if (ix >= 64)151return AH_FALSE;152if (ix >= 32) {153val = OS_REG_READ(ah, AR_MCAST_FIL1);154OS_REG_WRITE(ah, AR_MCAST_FIL1, (val | (1<<(ix-32))));155} else {156val = OS_REG_READ(ah, AR_MCAST_FIL0);157OS_REG_WRITE(ah, AR_MCAST_FIL0, (val | (1<<ix)));158}159return AH_TRUE;160}161162/*163* Get the receive filter.164*/165uint32_t166ar5212GetRxFilter(struct ath_hal *ah)167{168uint32_t bits = OS_REG_READ(ah, AR_RX_FILTER);169uint32_t phybits = OS_REG_READ(ah, AR_PHY_ERR);170if (phybits & AR_PHY_ERR_RADAR)171bits |= HAL_RX_FILTER_PHYRADAR;172if (phybits & (AR_PHY_ERR_OFDM_TIMING|AR_PHY_ERR_CCK_TIMING))173bits |= HAL_RX_FILTER_PHYERR;174if (AH_PRIVATE(ah)->ah_caps.halBssidMatchSupport &&175(AH5212(ah)->ah_miscMode & AR_MISC_MODE_BSSID_MATCH_FORCE))176bits |= HAL_RX_FILTER_BSSID;177return bits;178}179180/*181* Set the receive filter.182*/183void184ar5212SetRxFilter(struct ath_hal *ah, uint32_t bits)185{186struct ath_hal_5212 *ahp = AH5212(ah);187uint32_t phybits;188189OS_REG_WRITE(ah, AR_RX_FILTER,190bits &~ (HAL_RX_FILTER_PHYRADAR|HAL_RX_FILTER_PHYERR|191HAL_RX_FILTER_BSSID));192phybits = 0;193if (bits & HAL_RX_FILTER_PHYRADAR)194phybits |= AR_PHY_ERR_RADAR;195if (bits & HAL_RX_FILTER_PHYERR)196phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;197OS_REG_WRITE(ah, AR_PHY_ERR, phybits);198if (phybits) {199OS_REG_WRITE(ah, AR_RXCFG,200OS_REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);201} else {202OS_REG_WRITE(ah, AR_RXCFG,203OS_REG_READ(ah, AR_RXCFG) &~ AR_RXCFG_ZLFDMA);204}205if (AH_PRIVATE(ah)->ah_caps.halBssidMatchSupport) {206if (bits & HAL_RX_FILTER_BSSID)207ahp->ah_miscMode |= AR_MISC_MODE_BSSID_MATCH_FORCE;208else209ahp->ah_miscMode &= ~AR_MISC_MODE_BSSID_MATCH_FORCE;210OS_REG_WRITE(ah, AR_MISC_MODE, OS_REG_READ(ah, AR_MISC_MODE) | ahp->ah_miscMode);211}212}213214/*215* Initialize RX descriptor, by clearing the status and setting216* the size (and any other flags).217*/218HAL_BOOL219ar5212SetupRxDesc(struct ath_hal *ah, struct ath_desc *ds,220uint32_t size, u_int flags)221{222struct ar5212_desc *ads = AR5212DESC(ds);223224HALASSERT((size &~ AR_BufLen) == 0);225226ads->ds_ctl0 = 0;227ads->ds_ctl1 = size & AR_BufLen;228229if (flags & HAL_RXDESC_INTREQ)230ads->ds_ctl1 |= AR_RxInterReq;231ads->ds_rxstatus0 = ads->ds_rxstatus1 = 0;232233return AH_TRUE;234}235236/*237* Process an RX descriptor, and return the status to the caller.238* Copy some hardware specific items into the software portion239* of the descriptor.240*241* NB: the caller is responsible for validating the memory contents242* of the descriptor (e.g. flushing any cached copy).243*/244HAL_STATUS245ar5212ProcRxDesc(struct ath_hal *ah, struct ath_desc *ds,246uint32_t pa, struct ath_desc *nds, uint64_t tsf,247struct ath_rx_status *rs)248{249struct ar5212_desc *ads = AR5212DESC(ds);250struct ar5212_desc *ands = AR5212DESC(nds);251252if ((ads->ds_rxstatus1 & AR_Done) == 0)253return HAL_EINPROGRESS;254/*255* Given the use of a self-linked tail be very sure that the hw is256* done with this descriptor; the hw may have done this descriptor257* once and picked it up again...make sure the hw has moved on.258*/259if ((ands->ds_rxstatus1&AR_Done) == 0 && OS_REG_READ(ah, AR_RXDP) == pa)260return HAL_EINPROGRESS;261262rs->rs_datalen = ads->ds_rxstatus0 & AR_DataLen;263rs->rs_tstamp = MS(ads->ds_rxstatus1, AR_RcvTimestamp);264rs->rs_status = 0;265rs->rs_rssi = MS(ads->ds_rxstatus0, AR_RcvSigStrength);266/* discard invalid h/w rssi data */267if (rs->rs_rssi == -128)268rs->rs_rssi = 0;269if (ads->ds_rxstatus1 & AR_KeyIdxValid)270rs->rs_keyix = MS(ads->ds_rxstatus1, AR_KeyIdx);271else272rs->rs_keyix = HAL_RXKEYIX_INVALID;273if (ads->ds_rxstatus1 & AR_KeyCacheMiss)274rs->rs_status |= HAL_RXERR_KEYMISS;275/* NB: caller expected to do rate table mapping */276rs->rs_rate = MS(ads->ds_rxstatus0, AR_RcvRate);277rs->rs_antenna = MS(ads->ds_rxstatus0, AR_RcvAntenna);278rs->rs_more = (ads->ds_rxstatus0 & AR_More) ? 1 : 0;279280/*281* The AR5413 (at least) sometimes sets both AR_CRCErr and282* AR_PHYErr when reporting radar pulses. In this instance283* set HAL_RXERR_PHY as well as HAL_RXERR_CRC and284* let the driver layer figure out what to do.285*286* See PR kern/169362.287*/288if ((ads->ds_rxstatus1 & AR_FrmRcvOK) == 0) {289/*290* These four bits should not be set together. The291* 5212 spec states a Michael error can only occur if292* DecryptCRCErr not set (and TKIP is used). Experience293* indicates however that you can also get Michael errors294* when a CRC error is detected, but these are specious.295* Consequently we filter them out here so we don't296* confuse and/or complicate drivers.297*/298if (ads->ds_rxstatus1 & AR_PHYErr) {299u_int phyerr;300301rs->rs_status |= HAL_RXERR_PHY;302phyerr = MS(ads->ds_rxstatus1, AR_PHYErrCode);303rs->rs_phyerr = phyerr;304if (!AH5212(ah)->ah_hasHwPhyCounters &&305phyerr != HAL_PHYERR_RADAR)306ar5212AniPhyErrReport(ah, rs);307}308309if (ads->ds_rxstatus1 & AR_CRCErr)310rs->rs_status |= HAL_RXERR_CRC;311else if (ads->ds_rxstatus1 & AR_DecryptCRCErr)312rs->rs_status |= HAL_RXERR_DECRYPT;313else if (ads->ds_rxstatus1 & AR_MichaelErr)314rs->rs_status |= HAL_RXERR_MIC;315}316return HAL_OK;317}318319320