Path: blob/main/sys/dev/ath/ath_hal/ar5210/ar5210_recv.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"22#include "ah_desc.h"2324#include "ar5210/ar5210.h"25#include "ar5210/ar5210reg.h"26#include "ar5210/ar5210desc.h"2728/*29* Get the RXDP.30*/31uint32_t32ar5210GetRxDP(struct ath_hal *ah, HAL_RX_QUEUE qtype)33{3435HALASSERT(qtype == HAL_RX_QUEUE_HP);36return OS_REG_READ(ah, AR_RXDP);37}3839/*40* Set the RxDP.41*/42void43ar5210SetRxDP(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);48}4950/*51* Set Receive Enable bits.52*/53void54ar5210EnableReceive(struct ath_hal *ah)55{56OS_REG_WRITE(ah, AR_CR, AR_CR_RXE);57}5859/*60* Stop Receive at the DMA engine61*/62HAL_BOOL63ar5210StopDmaReceive(struct ath_hal *ah)64{65int i;6667OS_REG_WRITE(ah, AR_CR, AR_CR_RXD); /* Set receive disable bit */68for (i = 0; i < 1000; i++) {69if ((OS_REG_READ(ah, AR_CR) & AR_CR_RXE) == 0)70return AH_TRUE;71OS_DELAY(10);72}73#ifdef AH_DEBUG74ath_hal_printf(ah, "ar5210: dma receive failed to stop in 10ms\n");75ath_hal_printf(ah, "AR_CR=0x%x\n", OS_REG_READ(ah, AR_CR));76ath_hal_printf(ah, "AR_DIAG_SW=0x%x\n", OS_REG_READ(ah, AR_DIAG_SW));77#endif78return AH_FALSE;79}8081/*82* Start Transmit at the PCU engine (unpause receive)83*/84void85ar5210StartPcuReceive(struct ath_hal *ah, HAL_BOOL is_scanning)86{87ar5210UpdateDiagReg(ah,88OS_REG_READ(ah, AR_DIAG_SW) & ~(AR_DIAG_SW_DIS_RX));89}9091/*92* Stop Transmit at the PCU engine (pause receive)93*/94void95ar5210StopPcuReceive(struct ath_hal *ah)96{97ar5210UpdateDiagReg(ah,98OS_REG_READ(ah, AR_DIAG_SW) | AR_DIAG_SW_DIS_RX);99}100101/*102* Set multicast filter 0 (lower 32-bits)103* filter 1 (upper 32-bits)104*/105void106ar5210SetMulticastFilter(struct ath_hal *ah, uint32_t filter0, uint32_t filter1)107{108OS_REG_WRITE(ah, AR_MCAST_FIL0, filter0);109OS_REG_WRITE(ah, AR_MCAST_FIL1, filter1);110}111112/*113* Clear multicast filter by index114*/115HAL_BOOL116ar5210ClrMulticastFilterIndex(struct ath_hal *ah, uint32_t ix)117{118uint32_t val;119120if (ix >= 64)121return AH_FALSE;122if (ix >= 32) {123val = OS_REG_READ(ah, AR_MCAST_FIL1);124OS_REG_WRITE(ah, AR_MCAST_FIL1, (val &~ (1<<(ix-32))));125} else {126val = OS_REG_READ(ah, AR_MCAST_FIL0);127OS_REG_WRITE(ah, AR_MCAST_FIL0, (val &~ (1<<ix)));128}129return AH_TRUE;130}131132/*133* Set multicast filter by index134*/135HAL_BOOL136ar5210SetMulticastFilterIndex(struct ath_hal *ah, uint32_t ix)137{138uint32_t val;139140if (ix >= 64)141return AH_FALSE;142if (ix >= 32) {143val = OS_REG_READ(ah, AR_MCAST_FIL1);144OS_REG_WRITE(ah, AR_MCAST_FIL1, (val | (1<<(ix-32))));145} else {146val = OS_REG_READ(ah, AR_MCAST_FIL0);147OS_REG_WRITE(ah, AR_MCAST_FIL0, (val | (1<<ix)));148}149return AH_TRUE;150}151152/*153* Return the receive packet filter.154*/155uint32_t156ar5210GetRxFilter(struct ath_hal *ah)157{158/* XXX can't be sure if promiscuous mode is set because of PHYRADAR */159return OS_REG_READ(ah, AR_RX_FILTER);160}161162/*163* Turn off/on bits in the receive packet filter.164*/165void166ar5210SetRxFilter(struct ath_hal *ah, uint32_t bits)167{168if (bits & HAL_RX_FILTER_PHYRADAR) {169/* must enable promiscuous mode to get radar */170bits = (bits &~ HAL_RX_FILTER_PHYRADAR) | AR_RX_FILTER_PROMISCUOUS;171}172OS_REG_WRITE(ah, AR_RX_FILTER, bits);173}174175/*176* Initialize RX descriptor, by clearing the status and clearing177* the size. This is not strictly HW dependent, but we want the178* control and status words to be opaque above the hal.179*/180HAL_BOOL181ar5210SetupRxDesc(struct ath_hal *ah, struct ath_desc *ds,182uint32_t size, u_int flags)183{184struct ar5210_desc *ads = AR5210DESC(ds);185186(void) flags;187188ads->ds_ctl0 = 0;189ads->ds_ctl1 = size & AR_BufLen;190if (ads->ds_ctl1 != size) {191HALDEBUG(ah, HAL_DEBUG_ANY, "%s: buffer size %u too large\n",192__func__, size);193return AH_FALSE;194}195if (flags & HAL_RXDESC_INTREQ)196ads->ds_ctl1 |= AR_RxInterReq;197ads->ds_status0 = ads->ds_status1 = 0;198199return AH_TRUE;200}201202/*203* Process an RX descriptor, and return the status to the caller.204* Copy some hardware specific items into the software portion205* of the descriptor.206*207* NB: the caller is responsible for validating the memory contents208* of the descriptor (e.g. flushing any cached copy).209*/210HAL_STATUS211ar5210ProcRxDesc(struct ath_hal *ah, struct ath_desc *ds,212uint32_t pa, struct ath_desc *nds, uint64_t tsf,213struct ath_rx_status *rs)214{215struct ar5210_desc *ads = AR5210DESC(ds);216struct ar5210_desc *ands = AR5210DESC(nds);217uint32_t now, rstamp;218219if ((ads->ds_status1 & AR_Done) == 0)220return HAL_EINPROGRESS;221/*222* Given the use of a self-linked tail be very sure that the hw is223* done with this descriptor; the hw may have done this descriptor224* once and picked it up again...make sure the hw has moved on.225*/226if ((ands->ds_status1 & AR_Done) == 0 && OS_REG_READ(ah, AR_RXDP) == pa)227return HAL_EINPROGRESS;228229rs->rs_datalen = ads->ds_status0 & AR_DataLen;230rstamp = MS(ads->ds_status1, AR_RcvTimestamp);231/*232* Convert timestamp. The value in the233* descriptor is bits [10..22] of the TSF.234*/235now = (OS_REG_READ(ah, AR_TSF_L32) >> 10) & 0xffff;236if ((now & 0x1fff) < rstamp)237rstamp |= (now - 0x2000) & 0xffff;238else239rstamp |= now;240/* NB: keep only 15 bits for consistency w/ other chips */241rs->rs_tstamp = rstamp & 0x7fff;242rs->rs_status = 0;243if ((ads->ds_status1 & AR_FrmRcvOK) == 0) {244if (ads->ds_status1 & AR_CRCErr)245rs->rs_status |= HAL_RXERR_CRC;246else if (ads->ds_status1 & AR_DecryptCRCErr)247rs->rs_status |= HAL_RXERR_DECRYPT;248else if (ads->ds_status1 & AR_FIFOOverrun)249rs->rs_status |= HAL_RXERR_FIFO;250else {251rs->rs_status |= HAL_RXERR_PHY;252rs->rs_phyerr =253(ads->ds_status1 & AR_PHYErr) >> AR_PHYErr_S;254}255}256/* XXX what about KeyCacheMiss? */257rs->rs_rssi = MS(ads->ds_status0, AR_RcvSigStrength);258if (ads->ds_status1 & AR_KeyIdxValid)259rs->rs_keyix = MS(ads->ds_status1, AR_KeyIdx);260else261rs->rs_keyix = HAL_RXKEYIX_INVALID;262/* NB: caller expected to do rate table mapping */263rs->rs_rate = MS(ads->ds_status0, AR_RcvRate);264rs->rs_antenna = (ads->ds_status0 & AR_RcvAntenna) ? 1 : 0;265rs->rs_more = (ads->ds_status0 & AR_More) ? 1 : 0;266267return HAL_OK;268}269270271