1e60c4fc2SAdrian Chadd /*- 2718cf2ccSPedro F. Giffuni * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3718cf2ccSPedro F. Giffuni * 4e60c4fc2SAdrian Chadd * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting 5e60c4fc2SAdrian Chadd * All rights reserved. 6e60c4fc2SAdrian Chadd * 7e60c4fc2SAdrian Chadd * Redistribution and use in source and binary forms, with or without 8e60c4fc2SAdrian Chadd * modification, are permitted provided that the following conditions 9e60c4fc2SAdrian Chadd * are met: 10e60c4fc2SAdrian Chadd * 1. Redistributions of source code must retain the above copyright 11e60c4fc2SAdrian Chadd * notice, this list of conditions and the following disclaimer, 12e60c4fc2SAdrian Chadd * without modification. 13e60c4fc2SAdrian Chadd * 2. Redistributions in binary form must reproduce at minimum a disclaimer 14e60c4fc2SAdrian Chadd * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any 15e60c4fc2SAdrian Chadd * redistribution must be conditioned upon including a substantially 16e60c4fc2SAdrian Chadd * similar Disclaimer requirement for further binary redistribution. 17e60c4fc2SAdrian Chadd * 18e60c4fc2SAdrian Chadd * NO WARRANTY 19e60c4fc2SAdrian Chadd * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20e60c4fc2SAdrian Chadd * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21e60c4fc2SAdrian Chadd * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY 22e60c4fc2SAdrian Chadd * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 23e60c4fc2SAdrian Chadd * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, 24e60c4fc2SAdrian Chadd * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25e60c4fc2SAdrian Chadd * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26e60c4fc2SAdrian Chadd * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 27e60c4fc2SAdrian Chadd * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28e60c4fc2SAdrian Chadd * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 29e60c4fc2SAdrian Chadd * THE POSSIBILITY OF SUCH DAMAGES. 30e60c4fc2SAdrian Chadd */ 31e60c4fc2SAdrian Chadd 32e60c4fc2SAdrian Chadd #include <sys/cdefs.h> 33e60c4fc2SAdrian Chadd __FBSDID("$FreeBSD$"); 34e60c4fc2SAdrian Chadd 35e60c4fc2SAdrian Chadd /* 36e60c4fc2SAdrian Chadd * Driver for the Atheros Wireless LAN controller. 37e60c4fc2SAdrian Chadd * 38e60c4fc2SAdrian Chadd * This software is derived from work of Atsushi Onoe; his contribution 39e60c4fc2SAdrian Chadd * is greatly appreciated. 40e60c4fc2SAdrian Chadd */ 41e60c4fc2SAdrian Chadd 42e60c4fc2SAdrian Chadd #include "opt_inet.h" 43e60c4fc2SAdrian Chadd #include "opt_ath.h" 44e60c4fc2SAdrian Chadd /* 45e60c4fc2SAdrian Chadd * This is needed for register operations which are performed 46e60c4fc2SAdrian Chadd * by the driver - eg, calls to ath_hal_gettsf32(). 47e60c4fc2SAdrian Chadd * 48e60c4fc2SAdrian Chadd * It's also required for any AH_DEBUG checks in here, eg the 49e60c4fc2SAdrian Chadd * module dependencies. 50e60c4fc2SAdrian Chadd */ 51e60c4fc2SAdrian Chadd #include "opt_ah.h" 52e60c4fc2SAdrian Chadd #include "opt_wlan.h" 53e60c4fc2SAdrian Chadd 54e60c4fc2SAdrian Chadd #include <sys/param.h> 55e60c4fc2SAdrian Chadd #include <sys/systm.h> 56e60c4fc2SAdrian Chadd #include <sys/sysctl.h> 57e60c4fc2SAdrian Chadd #include <sys/mbuf.h> 58e60c4fc2SAdrian Chadd #include <sys/malloc.h> 59e60c4fc2SAdrian Chadd #include <sys/lock.h> 60e60c4fc2SAdrian Chadd #include <sys/mutex.h> 61e60c4fc2SAdrian Chadd #include <sys/kernel.h> 62e60c4fc2SAdrian Chadd #include <sys/socket.h> 63e60c4fc2SAdrian Chadd #include <sys/sockio.h> 64e60c4fc2SAdrian Chadd #include <sys/errno.h> 65e60c4fc2SAdrian Chadd #include <sys/callout.h> 66e60c4fc2SAdrian Chadd #include <sys/bus.h> 67e60c4fc2SAdrian Chadd #include <sys/endian.h> 68e60c4fc2SAdrian Chadd #include <sys/kthread.h> 69e60c4fc2SAdrian Chadd #include <sys/taskqueue.h> 70e60c4fc2SAdrian Chadd #include <sys/priv.h> 71e60c4fc2SAdrian Chadd #include <sys/module.h> 72e60c4fc2SAdrian Chadd #include <sys/ktr.h> 73e60c4fc2SAdrian Chadd #include <sys/smp.h> /* for mp_ncpus */ 74e60c4fc2SAdrian Chadd 75e60c4fc2SAdrian Chadd #include <machine/bus.h> 76e60c4fc2SAdrian Chadd 77e60c4fc2SAdrian Chadd #include <net/if.h> 7876039bc8SGleb Smirnoff #include <net/if_var.h> 79e60c4fc2SAdrian Chadd #include <net/if_dl.h> 80e60c4fc2SAdrian Chadd #include <net/if_media.h> 81e60c4fc2SAdrian Chadd #include <net/if_types.h> 82e60c4fc2SAdrian Chadd #include <net/if_arp.h> 83e60c4fc2SAdrian Chadd #include <net/ethernet.h> 84e60c4fc2SAdrian Chadd #include <net/if_llc.h> 85e60c4fc2SAdrian Chadd 86e60c4fc2SAdrian Chadd #include <net80211/ieee80211_var.h> 87e60c4fc2SAdrian Chadd #include <net80211/ieee80211_regdomain.h> 88e60c4fc2SAdrian Chadd #ifdef IEEE80211_SUPPORT_SUPERG 89e60c4fc2SAdrian Chadd #include <net80211/ieee80211_superg.h> 90e60c4fc2SAdrian Chadd #endif 91e60c4fc2SAdrian Chadd #ifdef IEEE80211_SUPPORT_TDMA 92e60c4fc2SAdrian Chadd #include <net80211/ieee80211_tdma.h> 93e60c4fc2SAdrian Chadd #endif 94e60c4fc2SAdrian Chadd 95e60c4fc2SAdrian Chadd #include <net/bpf.h> 96e60c4fc2SAdrian Chadd 97e60c4fc2SAdrian Chadd #ifdef INET 98e60c4fc2SAdrian Chadd #include <netinet/in.h> 99e60c4fc2SAdrian Chadd #include <netinet/if_ether.h> 100e60c4fc2SAdrian Chadd #endif 101e60c4fc2SAdrian Chadd 102e60c4fc2SAdrian Chadd #include <dev/ath/if_athvar.h> 103e60c4fc2SAdrian Chadd #include <dev/ath/ath_hal/ah_devid.h> /* XXX for softled */ 104e60c4fc2SAdrian Chadd #include <dev/ath/ath_hal/ah_diagcodes.h> 105e60c4fc2SAdrian Chadd 106e60c4fc2SAdrian Chadd #include <dev/ath/if_ath_debug.h> 107e60c4fc2SAdrian Chadd #include <dev/ath/if_ath_misc.h> 108e60c4fc2SAdrian Chadd #include <dev/ath/if_ath_tsf.h> 109e60c4fc2SAdrian Chadd #include <dev/ath/if_ath_tx.h> 110e60c4fc2SAdrian Chadd #include <dev/ath/if_ath_sysctl.h> 111e60c4fc2SAdrian Chadd #include <dev/ath/if_ath_led.h> 112e60c4fc2SAdrian Chadd #include <dev/ath/if_ath_keycache.h> 113e60c4fc2SAdrian Chadd #include <dev/ath/if_ath_rx.h> 114a35dae8dSAdrian Chadd #include <dev/ath/if_ath_beacon.h> 115e60c4fc2SAdrian Chadd #include <dev/ath/if_athdfs.h> 116b45de1ebSAdrian Chadd #include <dev/ath/if_ath_descdma.h> 117e60c4fc2SAdrian Chadd 118e60c4fc2SAdrian Chadd #ifdef ATH_TX99_DIAG 119e60c4fc2SAdrian Chadd #include <dev/ath/ath_tx99/ath_tx99.h> 120e60c4fc2SAdrian Chadd #endif 121e60c4fc2SAdrian Chadd 122b69b0dccSAdrian Chadd #ifdef ATH_DEBUG_ALQ 123b69b0dccSAdrian Chadd #include <dev/ath/if_ath_alq.h> 124b69b0dccSAdrian Chadd #endif 125b69b0dccSAdrian Chadd 126216ca234SAdrian Chadd #include <dev/ath/if_ath_lna_div.h> 127216ca234SAdrian Chadd 128e60c4fc2SAdrian Chadd /* 129e60c4fc2SAdrian Chadd * Calculate the receive filter according to the 130e60c4fc2SAdrian Chadd * operating mode and state: 131e60c4fc2SAdrian Chadd * 132e60c4fc2SAdrian Chadd * o always accept unicast, broadcast, and multicast traffic 133e60c4fc2SAdrian Chadd * o accept PHY error frames when hardware doesn't have MIB support 134e60c4fc2SAdrian Chadd * to count and we need them for ANI (sta mode only until recently) 135e60c4fc2SAdrian Chadd * and we are not scanning (ANI is disabled) 136e60c4fc2SAdrian Chadd * NB: older hal's add rx filter bits out of sight and we need to 137e60c4fc2SAdrian Chadd * blindly preserve them 138e60c4fc2SAdrian Chadd * o probe request frames are accepted only when operating in 139e60c4fc2SAdrian Chadd * hostap, adhoc, mesh, or monitor modes 140e60c4fc2SAdrian Chadd * o enable promiscuous mode 141e60c4fc2SAdrian Chadd * - when in monitor mode 142e60c4fc2SAdrian Chadd * - if interface marked PROMISC (assumes bridge setting is filtered) 143e60c4fc2SAdrian Chadd * o accept beacons: 144e60c4fc2SAdrian Chadd * - when operating in station mode for collecting rssi data when 145e60c4fc2SAdrian Chadd * the station is otherwise quiet, or 146e60c4fc2SAdrian Chadd * - when operating in adhoc mode so the 802.11 layer creates 147e60c4fc2SAdrian Chadd * node table entries for peers, 148e60c4fc2SAdrian Chadd * - when scanning 149e60c4fc2SAdrian Chadd * - when doing s/w beacon miss (e.g. for ap+sta) 150e60c4fc2SAdrian Chadd * - when operating in ap mode in 11g to detect overlapping bss that 151e60c4fc2SAdrian Chadd * require protection 152e60c4fc2SAdrian Chadd * - when operating in mesh mode to detect neighbors 153e60c4fc2SAdrian Chadd * o accept control frames: 154e60c4fc2SAdrian Chadd * - when in monitor mode 155e60c4fc2SAdrian Chadd * XXX HT protection for 11n 156e60c4fc2SAdrian Chadd */ 157e60c4fc2SAdrian Chadd u_int32_t 158e60c4fc2SAdrian Chadd ath_calcrxfilter(struct ath_softc *sc) 159e60c4fc2SAdrian Chadd { 1607a79cebfSGleb Smirnoff struct ieee80211com *ic = &sc->sc_ic; 161e60c4fc2SAdrian Chadd u_int32_t rfilt; 162e60c4fc2SAdrian Chadd 163e60c4fc2SAdrian Chadd rfilt = HAL_RX_FILTER_UCAST | HAL_RX_FILTER_BCAST | HAL_RX_FILTER_MCAST; 164e60c4fc2SAdrian Chadd if (!sc->sc_needmib && !sc->sc_scanning) 165e60c4fc2SAdrian Chadd rfilt |= HAL_RX_FILTER_PHYERR; 166e60c4fc2SAdrian Chadd if (ic->ic_opmode != IEEE80211_M_STA) 167e60c4fc2SAdrian Chadd rfilt |= HAL_RX_FILTER_PROBEREQ; 168e60c4fc2SAdrian Chadd /* XXX ic->ic_monvaps != 0? */ 1697a79cebfSGleb Smirnoff if (ic->ic_opmode == IEEE80211_M_MONITOR || ic->ic_promisc > 0) 170e60c4fc2SAdrian Chadd rfilt |= HAL_RX_FILTER_PROM; 171f5c30c4eSAdrian Chadd 172f5c30c4eSAdrian Chadd /* 173f5c30c4eSAdrian Chadd * Only listen to all beacons if we're scanning. 174f5c30c4eSAdrian Chadd * 175f5c30c4eSAdrian Chadd * Otherwise we only really need to hear beacons from 176f5c30c4eSAdrian Chadd * our own BSSID. 17794a88508SAdrian Chadd * 17894a88508SAdrian Chadd * IBSS? software beacon miss? Just receive all beacons. 17994a88508SAdrian Chadd * We need to hear beacons/probe requests from everyone so 18094a88508SAdrian Chadd * we can merge ibss. 181f5c30c4eSAdrian Chadd */ 18294a88508SAdrian Chadd if (ic->ic_opmode == IEEE80211_M_IBSS || sc->sc_swbmiss) { 18394a88508SAdrian Chadd rfilt |= HAL_RX_FILTER_BEACON; 18494a88508SAdrian Chadd } else if (ic->ic_opmode == IEEE80211_M_STA) { 185f5c30c4eSAdrian Chadd if (sc->sc_do_mybeacon && ! sc->sc_scanning) { 186f5c30c4eSAdrian Chadd rfilt |= HAL_RX_FILTER_MYBEACON; 187f5c30c4eSAdrian Chadd } else { /* scanning, non-mybeacon chips */ 188e60c4fc2SAdrian Chadd rfilt |= HAL_RX_FILTER_BEACON; 189f5c30c4eSAdrian Chadd } 190f5c30c4eSAdrian Chadd } 191f5c30c4eSAdrian Chadd 192e60c4fc2SAdrian Chadd /* 193e60c4fc2SAdrian Chadd * NB: We don't recalculate the rx filter when 194e60c4fc2SAdrian Chadd * ic_protmode changes; otherwise we could do 195e60c4fc2SAdrian Chadd * this only when ic_protmode != NONE. 196e60c4fc2SAdrian Chadd */ 197e60c4fc2SAdrian Chadd if (ic->ic_opmode == IEEE80211_M_HOSTAP && 198e60c4fc2SAdrian Chadd IEEE80211_IS_CHAN_ANYG(ic->ic_curchan)) 199e60c4fc2SAdrian Chadd rfilt |= HAL_RX_FILTER_BEACON; 200e60c4fc2SAdrian Chadd 201e60c4fc2SAdrian Chadd /* 202e60c4fc2SAdrian Chadd * Enable hardware PS-POLL RX only for hostap mode; 203e60c4fc2SAdrian Chadd * STA mode sends PS-POLL frames but never 204e60c4fc2SAdrian Chadd * receives them. 205e60c4fc2SAdrian Chadd */ 206e60c4fc2SAdrian Chadd if (ath_hal_getcapability(sc->sc_ah, HAL_CAP_PSPOLL, 207e60c4fc2SAdrian Chadd 0, NULL) == HAL_OK && 208e60c4fc2SAdrian Chadd ic->ic_opmode == IEEE80211_M_HOSTAP) 209e60c4fc2SAdrian Chadd rfilt |= HAL_RX_FILTER_PSPOLL; 210e60c4fc2SAdrian Chadd 211e60c4fc2SAdrian Chadd if (sc->sc_nmeshvaps) { 212e60c4fc2SAdrian Chadd rfilt |= HAL_RX_FILTER_BEACON; 213e60c4fc2SAdrian Chadd if (sc->sc_hasbmatch) 214e60c4fc2SAdrian Chadd rfilt |= HAL_RX_FILTER_BSSID; 215e60c4fc2SAdrian Chadd else 216e60c4fc2SAdrian Chadd rfilt |= HAL_RX_FILTER_PROM; 217e60c4fc2SAdrian Chadd } 218e60c4fc2SAdrian Chadd if (ic->ic_opmode == IEEE80211_M_MONITOR) 219e60c4fc2SAdrian Chadd rfilt |= HAL_RX_FILTER_CONTROL; 220e60c4fc2SAdrian Chadd 221e60c4fc2SAdrian Chadd /* 222e60c4fc2SAdrian Chadd * Enable RX of compressed BAR frames only when doing 223e60c4fc2SAdrian Chadd * 802.11n. Required for A-MPDU. 224e60c4fc2SAdrian Chadd */ 225e60c4fc2SAdrian Chadd if (IEEE80211_IS_CHAN_HT(ic->ic_curchan)) 226e60c4fc2SAdrian Chadd rfilt |= HAL_RX_FILTER_COMPBAR; 227e60c4fc2SAdrian Chadd 228e60c4fc2SAdrian Chadd /* 229e60c4fc2SAdrian Chadd * Enable radar PHY errors if requested by the 230e60c4fc2SAdrian Chadd * DFS module. 231e60c4fc2SAdrian Chadd */ 232e60c4fc2SAdrian Chadd if (sc->sc_dodfs) 233e60c4fc2SAdrian Chadd rfilt |= HAL_RX_FILTER_PHYRADAR; 234e60c4fc2SAdrian Chadd 235f29c6bdeSAdrian Chadd /* 236f29c6bdeSAdrian Chadd * Enable spectral PHY errors if requested by the 237f29c6bdeSAdrian Chadd * spectral module. 238f29c6bdeSAdrian Chadd */ 239f29c6bdeSAdrian Chadd if (sc->sc_dospectral) 240f29c6bdeSAdrian Chadd rfilt |= HAL_RX_FILTER_PHYRADAR; 241f29c6bdeSAdrian Chadd 2427a79cebfSGleb Smirnoff DPRINTF(sc, ATH_DEBUG_MODE, "%s: RX filter 0x%x, %s\n", 2437a79cebfSGleb Smirnoff __func__, rfilt, ieee80211_opmode_name[ic->ic_opmode]); 244e60c4fc2SAdrian Chadd return rfilt; 245e60c4fc2SAdrian Chadd } 246e60c4fc2SAdrian Chadd 247f8cc9b09SAdrian Chadd static int 248f8cc9b09SAdrian Chadd ath_legacy_rxbuf_init(struct ath_softc *sc, struct ath_buf *bf) 249e60c4fc2SAdrian Chadd { 250e60c4fc2SAdrian Chadd struct ath_hal *ah = sc->sc_ah; 251e60c4fc2SAdrian Chadd int error; 252e60c4fc2SAdrian Chadd struct mbuf *m; 253e60c4fc2SAdrian Chadd struct ath_desc *ds; 254e60c4fc2SAdrian Chadd 25567aaf739SAdrian Chadd /* XXX TODO: ATH_RX_LOCK_ASSERT(sc); */ 25667aaf739SAdrian Chadd 257e60c4fc2SAdrian Chadd m = bf->bf_m; 258e60c4fc2SAdrian Chadd if (m == NULL) { 259e60c4fc2SAdrian Chadd /* 260e60c4fc2SAdrian Chadd * NB: by assigning a page to the rx dma buffer we 261e60c4fc2SAdrian Chadd * implicitly satisfy the Atheros requirement that 262e60c4fc2SAdrian Chadd * this buffer be cache-line-aligned and sized to be 263e60c4fc2SAdrian Chadd * multiple of the cache line size. Not doing this 264e60c4fc2SAdrian Chadd * causes weird stuff to happen (for the 5210 at least). 265e60c4fc2SAdrian Chadd */ 266c6499eccSGleb Smirnoff m = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR); 267e60c4fc2SAdrian Chadd if (m == NULL) { 268e60c4fc2SAdrian Chadd DPRINTF(sc, ATH_DEBUG_ANY, 269e60c4fc2SAdrian Chadd "%s: no mbuf/cluster\n", __func__); 270e60c4fc2SAdrian Chadd sc->sc_stats.ast_rx_nombuf++; 271e60c4fc2SAdrian Chadd return ENOMEM; 272e60c4fc2SAdrian Chadd } 273e60c4fc2SAdrian Chadd m->m_pkthdr.len = m->m_len = m->m_ext.ext_size; 274e60c4fc2SAdrian Chadd 275e60c4fc2SAdrian Chadd error = bus_dmamap_load_mbuf_sg(sc->sc_dmat, 276e60c4fc2SAdrian Chadd bf->bf_dmamap, m, 277e60c4fc2SAdrian Chadd bf->bf_segs, &bf->bf_nseg, 278e60c4fc2SAdrian Chadd BUS_DMA_NOWAIT); 279e60c4fc2SAdrian Chadd if (error != 0) { 280e60c4fc2SAdrian Chadd DPRINTF(sc, ATH_DEBUG_ANY, 281e60c4fc2SAdrian Chadd "%s: bus_dmamap_load_mbuf_sg failed; error %d\n", 282e60c4fc2SAdrian Chadd __func__, error); 283e60c4fc2SAdrian Chadd sc->sc_stats.ast_rx_busdma++; 284e60c4fc2SAdrian Chadd m_freem(m); 285e60c4fc2SAdrian Chadd return error; 286e60c4fc2SAdrian Chadd } 287e60c4fc2SAdrian Chadd KASSERT(bf->bf_nseg == 1, 288e60c4fc2SAdrian Chadd ("multi-segment packet; nseg %u", bf->bf_nseg)); 289e60c4fc2SAdrian Chadd bf->bf_m = m; 290e60c4fc2SAdrian Chadd } 291e60c4fc2SAdrian Chadd bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap, BUS_DMASYNC_PREREAD); 292e60c4fc2SAdrian Chadd 293e60c4fc2SAdrian Chadd /* 294e60c4fc2SAdrian Chadd * Setup descriptors. For receive we always terminate 295e60c4fc2SAdrian Chadd * the descriptor list with a self-linked entry so we'll 296e60c4fc2SAdrian Chadd * not get overrun under high load (as can happen with a 297e60c4fc2SAdrian Chadd * 5212 when ANI processing enables PHY error frames). 298e60c4fc2SAdrian Chadd * 299e60c4fc2SAdrian Chadd * To insure the last descriptor is self-linked we create 300e60c4fc2SAdrian Chadd * each descriptor as self-linked and add it to the end. As 301e60c4fc2SAdrian Chadd * each additional descriptor is added the previous self-linked 302e60c4fc2SAdrian Chadd * entry is ``fixed'' naturally. This should be safe even 303e60c4fc2SAdrian Chadd * if DMA is happening. When processing RX interrupts we 304e60c4fc2SAdrian Chadd * never remove/process the last, self-linked, entry on the 305e60c4fc2SAdrian Chadd * descriptor list. This insures the hardware always has 306e60c4fc2SAdrian Chadd * someplace to write a new frame. 307e60c4fc2SAdrian Chadd */ 308e60c4fc2SAdrian Chadd /* 309e60c4fc2SAdrian Chadd * 11N: we can no longer afford to self link the last descriptor. 310e60c4fc2SAdrian Chadd * MAC acknowledges BA status as long as it copies frames to host 311e60c4fc2SAdrian Chadd * buffer (or rx fifo). This can incorrectly acknowledge packets 312e60c4fc2SAdrian Chadd * to a sender if last desc is self-linked. 313e60c4fc2SAdrian Chadd */ 314e60c4fc2SAdrian Chadd ds = bf->bf_desc; 315e60c4fc2SAdrian Chadd if (sc->sc_rxslink) 316e60c4fc2SAdrian Chadd ds->ds_link = bf->bf_daddr; /* link to self */ 317e60c4fc2SAdrian Chadd else 318e60c4fc2SAdrian Chadd ds->ds_link = 0; /* terminate the list */ 319e60c4fc2SAdrian Chadd ds->ds_data = bf->bf_segs[0].ds_addr; 320e60c4fc2SAdrian Chadd ath_hal_setuprxdesc(ah, ds 321e60c4fc2SAdrian Chadd , m->m_len /* buffer size */ 322e60c4fc2SAdrian Chadd , 0 323e60c4fc2SAdrian Chadd ); 324e60c4fc2SAdrian Chadd 325e60c4fc2SAdrian Chadd if (sc->sc_rxlink != NULL) 326e60c4fc2SAdrian Chadd *sc->sc_rxlink = bf->bf_daddr; 327e60c4fc2SAdrian Chadd sc->sc_rxlink = &ds->ds_link; 328e60c4fc2SAdrian Chadd return 0; 329e60c4fc2SAdrian Chadd } 330e60c4fc2SAdrian Chadd 331e60c4fc2SAdrian Chadd /* 332e60c4fc2SAdrian Chadd * Intercept management frames to collect beacon rssi data 333e60c4fc2SAdrian Chadd * and to do ibss merges. 334e60c4fc2SAdrian Chadd */ 335e60c4fc2SAdrian Chadd void 336e60c4fc2SAdrian Chadd ath_recv_mgmt(struct ieee80211_node *ni, struct mbuf *m, 337c79f192cSAdrian Chadd int subtype, const struct ieee80211_rx_stats *rxs, int rssi, int nf) 338e60c4fc2SAdrian Chadd { 339e60c4fc2SAdrian Chadd struct ieee80211vap *vap = ni->ni_vap; 3403797bf08SAdrian Chadd struct ath_softc *sc = vap->iv_ic->ic_softc; 341f5c30c4eSAdrian Chadd uint64_t tsf_beacon_old, tsf_beacon; 342f5c30c4eSAdrian Chadd uint64_t nexttbtt; 343f5c30c4eSAdrian Chadd int64_t tsf_delta; 344f5c30c4eSAdrian Chadd int32_t tsf_delta_bmiss; 345f5c30c4eSAdrian Chadd int32_t tsf_remainder; 346f5c30c4eSAdrian Chadd uint64_t tsf_beacon_target; 3478cc3f9c9SAdrian Chadd int tsf_intval; 348f5c30c4eSAdrian Chadd 34931021a2bSAndriy Voskoboinyk tsf_beacon_old = ((uint64_t) le32dec(ni->ni_tstamp.data + 4)) << 32; 35031021a2bSAndriy Voskoboinyk tsf_beacon_old |= le32dec(ni->ni_tstamp.data); 351e60c4fc2SAdrian Chadd 3528cc3f9c9SAdrian Chadd #define TU_TO_TSF(_tu) (((u_int64_t)(_tu)) << 10) 3538cc3f9c9SAdrian Chadd tsf_intval = 1; 354add58488SAdrian Chadd if (ni->ni_intval > 0) { 3558cc3f9c9SAdrian Chadd tsf_intval = TU_TO_TSF(ni->ni_intval); 3568cc3f9c9SAdrian Chadd } 3578cc3f9c9SAdrian Chadd #undef TU_TO_TSF 3588cc3f9c9SAdrian Chadd 359e60c4fc2SAdrian Chadd /* 360e60c4fc2SAdrian Chadd * Call up first so subsequent work can use information 361e60c4fc2SAdrian Chadd * potentially stored in the node (e.g. for ibss merge). 362e60c4fc2SAdrian Chadd */ 363c79f192cSAdrian Chadd ATH_VAP(vap)->av_recv_mgmt(ni, m, subtype, rxs, rssi, nf); 364e60c4fc2SAdrian Chadd switch (subtype) { 365e60c4fc2SAdrian Chadd case IEEE80211_FC0_SUBTYPE_BEACON: 3667d450faaSAdrian Chadd /* 3677d450faaSAdrian Chadd * Always update the per-node beacon RSSI if we're hearing 3687d450faaSAdrian Chadd * beacons from that node. 3697d450faaSAdrian Chadd */ 3707d450faaSAdrian Chadd ATH_RSSI_LPF(ATH_NODE(ni)->an_node_stats.ns_avgbrssi, rssi); 371afa44333SAdrian Chadd 372afa44333SAdrian Chadd /* 373afa44333SAdrian Chadd * Only do the following processing if it's for 374afa44333SAdrian Chadd * the current BSS. 375afa44333SAdrian Chadd * 376afa44333SAdrian Chadd * In scan and IBSS mode we receive all beacons, 377afa44333SAdrian Chadd * which means we need to filter out stuff 378afa44333SAdrian Chadd * that isn't for us or we'll end up constantly 379afa44333SAdrian Chadd * trying to sync / merge to BSSes that aren't 380afa44333SAdrian Chadd * actually us. 381afa44333SAdrian Chadd */ 382857e0646SAdrian Chadd if ((vap->iv_opmode != IEEE80211_M_HOSTAP) && 383857e0646SAdrian Chadd IEEE80211_ADDR_EQ(ni->ni_bssid, vap->iv_bss->ni_bssid)) { 384e60c4fc2SAdrian Chadd /* update rssi statistics for use by the hal */ 385e60c4fc2SAdrian Chadd /* XXX unlocked check against vap->iv_bss? */ 386e60c4fc2SAdrian Chadd ATH_RSSI_LPF(sc->sc_halstats.ns_avgbrssi, rssi); 387f5c30c4eSAdrian Chadd 38831021a2bSAndriy Voskoboinyk tsf_beacon = ((uint64_t) le32dec(ni->ni_tstamp.data + 4)) << 32; 38931021a2bSAndriy Voskoboinyk tsf_beacon |= le32dec(ni->ni_tstamp.data); 390f5c30c4eSAdrian Chadd 391f5c30c4eSAdrian Chadd nexttbtt = ath_hal_getnexttbtt(sc->sc_ah); 392f5c30c4eSAdrian Chadd 393f5c30c4eSAdrian Chadd /* 394f5c30c4eSAdrian Chadd * Let's calculate the delta and remainder, so we can see 395f5c30c4eSAdrian Chadd * if the beacon timer from the AP is varying by more than 396f5c30c4eSAdrian Chadd * a few TU. (Which would be a huge, huge problem.) 397f5c30c4eSAdrian Chadd */ 398f5c30c4eSAdrian Chadd tsf_delta = (long long) tsf_beacon - (long long) tsf_beacon_old; 399f5c30c4eSAdrian Chadd 4008cc3f9c9SAdrian Chadd tsf_delta_bmiss = tsf_delta / tsf_intval; 401f5c30c4eSAdrian Chadd 402f5c30c4eSAdrian Chadd /* 403f5c30c4eSAdrian Chadd * If our delta is greater than half the beacon interval, 404f5c30c4eSAdrian Chadd * let's round the bmiss value up to the next beacon 405f5c30c4eSAdrian Chadd * interval. Ie, we're running really, really early 406f5c30c4eSAdrian Chadd * on the next beacon. 407f5c30c4eSAdrian Chadd */ 4088cc3f9c9SAdrian Chadd if (tsf_delta % tsf_intval > (tsf_intval / 2)) 409f5c30c4eSAdrian Chadd tsf_delta_bmiss ++; 410f5c30c4eSAdrian Chadd 411f5c30c4eSAdrian Chadd tsf_beacon_target = tsf_beacon_old + 4128cc3f9c9SAdrian Chadd (((unsigned long long) tsf_delta_bmiss) * (long long) tsf_intval); 413f5c30c4eSAdrian Chadd 414f5c30c4eSAdrian Chadd /* 4158cc3f9c9SAdrian Chadd * The remainder using '%' is between 0 .. intval-1. 416f5c30c4eSAdrian Chadd * If we're actually running too fast, then the remainder 4178cc3f9c9SAdrian Chadd * will be some large number just under intval-1. 418f5c30c4eSAdrian Chadd * So we need to look at whether we're running 419f5c30c4eSAdrian Chadd * before or after the target beacon interval 420f5c30c4eSAdrian Chadd * and if we are, modify how we do the remainder 421f5c30c4eSAdrian Chadd * calculation. 422f5c30c4eSAdrian Chadd */ 423f5c30c4eSAdrian Chadd if (tsf_beacon < tsf_beacon_target) { 4248cc3f9c9SAdrian Chadd tsf_remainder = 4258cc3f9c9SAdrian Chadd -(tsf_intval - ((tsf_beacon - tsf_beacon_old) % tsf_intval)); 426f5c30c4eSAdrian Chadd } else { 4278cc3f9c9SAdrian Chadd tsf_remainder = (tsf_beacon - tsf_beacon_old) % tsf_intval; 428f5c30c4eSAdrian Chadd } 429f5c30c4eSAdrian Chadd 430857e0646SAdrian Chadd DPRINTF(sc, ATH_DEBUG_BEACON, "%s: %s: old_tsf=%llu (%u), new_tsf=%llu (%u), target_tsf=%llu (%u), delta=%lld, bmiss=%d, remainder=%d\n", 431f5c30c4eSAdrian Chadd __func__, 432857e0646SAdrian Chadd ieee80211_get_vap_ifname(vap), 433f5c30c4eSAdrian Chadd (unsigned long long) tsf_beacon_old, 434dc87d071SAdrian Chadd (unsigned int) (tsf_beacon_old >> 10), 435f5c30c4eSAdrian Chadd (unsigned long long) tsf_beacon, 436dc87d071SAdrian Chadd (unsigned int ) (tsf_beacon >> 10), 437f5c30c4eSAdrian Chadd (unsigned long long) tsf_beacon_target, 438dc87d071SAdrian Chadd (unsigned int) (tsf_beacon_target >> 10), 439f5c30c4eSAdrian Chadd (long long) tsf_delta, 440f5c30c4eSAdrian Chadd tsf_delta_bmiss, 441f5c30c4eSAdrian Chadd tsf_remainder); 442f5c30c4eSAdrian Chadd 443857e0646SAdrian Chadd DPRINTF(sc, ATH_DEBUG_BEACON, "%s: %s: ni=%6D bssid=%6D tsf=%llu (%u), nexttbtt=%llu (%u), delta=%d\n", 444f5c30c4eSAdrian Chadd __func__, 445857e0646SAdrian Chadd ieee80211_get_vap_ifname(vap), 446857e0646SAdrian Chadd ni->ni_bssid, ":", 447857e0646SAdrian Chadd vap->iv_bss->ni_bssid, ":", 448f5c30c4eSAdrian Chadd (unsigned long long) tsf_beacon, 449dc87d071SAdrian Chadd (unsigned int) (tsf_beacon >> 10), 450f5c30c4eSAdrian Chadd (unsigned long long) nexttbtt, 451dc87d071SAdrian Chadd (unsigned int) (nexttbtt >> 10), 4528cc3f9c9SAdrian Chadd (int32_t) tsf_beacon - (int32_t) nexttbtt + tsf_intval); 453f5c30c4eSAdrian Chadd 454f6287cc6SAdrian Chadd /* 455f6287cc6SAdrian Chadd * We only do syncbeacon on STA VAPs; not on IBSS; 456f6287cc6SAdrian Chadd * but don't do it with swbmiss enabled or we 457f6287cc6SAdrian Chadd * may end up overwriting AP mode beacon config. 458f6287cc6SAdrian Chadd * 459f6287cc6SAdrian Chadd * The driver (and net80211) should be smarter about 460f6287cc6SAdrian Chadd * this.. 461f6287cc6SAdrian Chadd */ 462afa44333SAdrian Chadd if (vap->iv_opmode == IEEE80211_M_STA && 463afa44333SAdrian Chadd sc->sc_syncbeacon && 464f6287cc6SAdrian Chadd (!sc->sc_swbmiss) && 465f5c30c4eSAdrian Chadd ni == vap->iv_bss && 466*f858e928SAdrian Chadd ((vap->iv_flags_ext & IEEE80211_FEXT_SWBMISS) == 0) && 467f5c30c4eSAdrian Chadd (vap->iv_state == IEEE80211_S_RUN || vap->iv_state == IEEE80211_S_SLEEP)) { 468f5c30c4eSAdrian Chadd DPRINTF(sc, ATH_DEBUG_BEACON, 469f5c30c4eSAdrian Chadd "%s: syncbeacon=1; syncing\n", 470f5c30c4eSAdrian Chadd __func__); 471e60c4fc2SAdrian Chadd /* 472e60c4fc2SAdrian Chadd * Resync beacon timers using the tsf of the beacon 473e60c4fc2SAdrian Chadd * frame we just received. 474e60c4fc2SAdrian Chadd */ 475e60c4fc2SAdrian Chadd ath_beacon_config(sc, vap); 476f5c30c4eSAdrian Chadd sc->sc_syncbeacon = 0; 477e60c4fc2SAdrian Chadd } 478afa44333SAdrian Chadd } 479f5c30c4eSAdrian Chadd 480e60c4fc2SAdrian Chadd /* fall thru... */ 481e60c4fc2SAdrian Chadd case IEEE80211_FC0_SUBTYPE_PROBE_RESP: 482e60c4fc2SAdrian Chadd if (vap->iv_opmode == IEEE80211_M_IBSS && 483afa44333SAdrian Chadd vap->iv_state == IEEE80211_S_RUN && 484afa44333SAdrian Chadd ieee80211_ibss_merge_check(ni)) { 485e60c4fc2SAdrian Chadd uint32_t rstamp = sc->sc_lastrs->rs_tstamp; 486e60c4fc2SAdrian Chadd uint64_t tsf = ath_extend_tsf(sc, rstamp, 487e60c4fc2SAdrian Chadd ath_hal_gettsf64(sc->sc_ah)); 488e60c4fc2SAdrian Chadd /* 489e60c4fc2SAdrian Chadd * Handle ibss merge as needed; check the tsf on the 490e60c4fc2SAdrian Chadd * frame before attempting the merge. The 802.11 spec 491e60c4fc2SAdrian Chadd * says the station should change it's bssid to match 492e60c4fc2SAdrian Chadd * the oldest station with the same ssid, where oldest 493e60c4fc2SAdrian Chadd * is determined by the tsf. Note that hardware 494e60c4fc2SAdrian Chadd * reconfiguration happens through callback to 495e60c4fc2SAdrian Chadd * ath_newstate as the state machine will go from 496e60c4fc2SAdrian Chadd * RUN -> RUN when this happens. 497e60c4fc2SAdrian Chadd */ 498e60c4fc2SAdrian Chadd if (le64toh(ni->ni_tstamp.tsf) >= tsf) { 499e60c4fc2SAdrian Chadd DPRINTF(sc, ATH_DEBUG_STATE, 500e60c4fc2SAdrian Chadd "ibss merge, rstamp %u tsf %ju " 501e60c4fc2SAdrian Chadd "tstamp %ju\n", rstamp, (uintmax_t)tsf, 502e60c4fc2SAdrian Chadd (uintmax_t)ni->ni_tstamp.tsf); 503e60c4fc2SAdrian Chadd (void) ieee80211_ibss_merge(ni); 504e60c4fc2SAdrian Chadd } 505e60c4fc2SAdrian Chadd } 506e60c4fc2SAdrian Chadd break; 507e60c4fc2SAdrian Chadd } 508e60c4fc2SAdrian Chadd } 509e60c4fc2SAdrian Chadd 510e1b5ab97SAdrian Chadd #ifdef ATH_ENABLE_RADIOTAP_VENDOR_EXT 511e1b5ab97SAdrian Chadd static void 5127a79cebfSGleb Smirnoff ath_rx_tap_vendor(struct ath_softc *sc, struct mbuf *m, 513e1b5ab97SAdrian Chadd const struct ath_rx_status *rs, u_int64_t tsf, int16_t nf) 514e1b5ab97SAdrian Chadd { 515e1b5ab97SAdrian Chadd 516e1b5ab97SAdrian Chadd /* Fill in the extension bitmap */ 517e1b5ab97SAdrian Chadd sc->sc_rx_th.wr_ext_bitmap = htole32(1 << ATH_RADIOTAP_VENDOR_HEADER); 518e1b5ab97SAdrian Chadd 519e1b5ab97SAdrian Chadd /* Fill in the vendor header */ 520e1b5ab97SAdrian Chadd sc->sc_rx_th.wr_vh.vh_oui[0] = 0x7f; 521e1b5ab97SAdrian Chadd sc->sc_rx_th.wr_vh.vh_oui[1] = 0x03; 522e1b5ab97SAdrian Chadd sc->sc_rx_th.wr_vh.vh_oui[2] = 0x00; 523e1b5ab97SAdrian Chadd 524e1b5ab97SAdrian Chadd /* XXX what should this be? */ 525e1b5ab97SAdrian Chadd sc->sc_rx_th.wr_vh.vh_sub_ns = 0; 526e1b5ab97SAdrian Chadd sc->sc_rx_th.wr_vh.vh_skip_len = 527e1b5ab97SAdrian Chadd htole16(sizeof(struct ath_radiotap_vendor_hdr)); 528e1b5ab97SAdrian Chadd 529e1b5ab97SAdrian Chadd /* General version info */ 530e1b5ab97SAdrian Chadd sc->sc_rx_th.wr_v.vh_version = 1; 531e1b5ab97SAdrian Chadd 532e1b5ab97SAdrian Chadd sc->sc_rx_th.wr_v.vh_rx_chainmask = sc->sc_rxchainmask; 533e1b5ab97SAdrian Chadd 534e1b5ab97SAdrian Chadd /* rssi */ 535e1b5ab97SAdrian Chadd sc->sc_rx_th.wr_v.rssi_ctl[0] = rs->rs_rssi_ctl[0]; 536e1b5ab97SAdrian Chadd sc->sc_rx_th.wr_v.rssi_ctl[1] = rs->rs_rssi_ctl[1]; 537e1b5ab97SAdrian Chadd sc->sc_rx_th.wr_v.rssi_ctl[2] = rs->rs_rssi_ctl[2]; 538e1b5ab97SAdrian Chadd sc->sc_rx_th.wr_v.rssi_ext[0] = rs->rs_rssi_ext[0]; 539e1b5ab97SAdrian Chadd sc->sc_rx_th.wr_v.rssi_ext[1] = rs->rs_rssi_ext[1]; 540e1b5ab97SAdrian Chadd sc->sc_rx_th.wr_v.rssi_ext[2] = rs->rs_rssi_ext[2]; 541e1b5ab97SAdrian Chadd 542e1b5ab97SAdrian Chadd /* evm */ 543e1b5ab97SAdrian Chadd sc->sc_rx_th.wr_v.evm[0] = rs->rs_evm0; 544e1b5ab97SAdrian Chadd sc->sc_rx_th.wr_v.evm[1] = rs->rs_evm1; 545e1b5ab97SAdrian Chadd sc->sc_rx_th.wr_v.evm[2] = rs->rs_evm2; 5461896b088SAdrian Chadd /* These are only populated from the AR9300 or later */ 5471896b088SAdrian Chadd sc->sc_rx_th.wr_v.evm[3] = rs->rs_evm3; 5481896b088SAdrian Chadd sc->sc_rx_th.wr_v.evm[4] = rs->rs_evm4; 549e1b5ab97SAdrian Chadd 5500e168bb8SAdrian Chadd /* direction */ 5510e168bb8SAdrian Chadd sc->sc_rx_th.wr_v.vh_flags = ATH_VENDOR_PKT_RX; 5520e168bb8SAdrian Chadd 5530e168bb8SAdrian Chadd /* RX rate */ 5540e168bb8SAdrian Chadd sc->sc_rx_th.wr_v.vh_rx_hwrate = rs->rs_rate; 5550e168bb8SAdrian Chadd 5560e168bb8SAdrian Chadd /* RX flags */ 5570e168bb8SAdrian Chadd sc->sc_rx_th.wr_v.vh_rs_flags = rs->rs_flags; 5580e168bb8SAdrian Chadd 5590e168bb8SAdrian Chadd if (rs->rs_isaggr) 5600e168bb8SAdrian Chadd sc->sc_rx_th.wr_v.vh_flags |= ATH_VENDOR_PKT_ISAGGR; 5610e168bb8SAdrian Chadd if (rs->rs_moreaggr) 5620e168bb8SAdrian Chadd sc->sc_rx_th.wr_v.vh_flags |= ATH_VENDOR_PKT_MOREAGGR; 5630e168bb8SAdrian Chadd 564e1b5ab97SAdrian Chadd /* phyerr info */ 5650e168bb8SAdrian Chadd if (rs->rs_status & HAL_RXERR_PHY) { 566e1b5ab97SAdrian Chadd sc->sc_rx_th.wr_v.vh_phyerr_code = rs->rs_phyerr; 5670e168bb8SAdrian Chadd sc->sc_rx_th.wr_v.vh_flags |= ATH_VENDOR_PKT_RXPHYERR; 5680e168bb8SAdrian Chadd } else { 569e1b5ab97SAdrian Chadd sc->sc_rx_th.wr_v.vh_phyerr_code = 0xff; 5700e168bb8SAdrian Chadd } 571e1b5ab97SAdrian Chadd sc->sc_rx_th.wr_v.vh_rs_status = rs->rs_status; 572e1b5ab97SAdrian Chadd sc->sc_rx_th.wr_v.vh_rssi = rs->rs_rssi; 573e1b5ab97SAdrian Chadd } 574e1b5ab97SAdrian Chadd #endif /* ATH_ENABLE_RADIOTAP_VENDOR_EXT */ 575e1b5ab97SAdrian Chadd 576e60c4fc2SAdrian Chadd static void 5777a79cebfSGleb Smirnoff ath_rx_tap(struct ath_softc *sc, struct mbuf *m, 578e60c4fc2SAdrian Chadd const struct ath_rx_status *rs, u_int64_t tsf, int16_t nf) 579e60c4fc2SAdrian Chadd { 580e60c4fc2SAdrian Chadd #define CHAN_HT20 htole32(IEEE80211_CHAN_HT20) 581e60c4fc2SAdrian Chadd #define CHAN_HT40U htole32(IEEE80211_CHAN_HT40U) 582e60c4fc2SAdrian Chadd #define CHAN_HT40D htole32(IEEE80211_CHAN_HT40D) 583e60c4fc2SAdrian Chadd #define CHAN_HT (CHAN_HT20|CHAN_HT40U|CHAN_HT40D) 584e60c4fc2SAdrian Chadd const HAL_RATE_TABLE *rt; 585e60c4fc2SAdrian Chadd uint8_t rix; 586e60c4fc2SAdrian Chadd 587e60c4fc2SAdrian Chadd rt = sc->sc_currates; 588e60c4fc2SAdrian Chadd KASSERT(rt != NULL, ("no rate table, mode %u", sc->sc_curmode)); 589e60c4fc2SAdrian Chadd rix = rt->rateCodeToIndex[rs->rs_rate]; 590e60c4fc2SAdrian Chadd sc->sc_rx_th.wr_rate = sc->sc_hwmap[rix].ieeerate; 591e60c4fc2SAdrian Chadd sc->sc_rx_th.wr_flags = sc->sc_hwmap[rix].rxflags; 592f46839b9SAdrian Chadd 593f46839b9SAdrian Chadd /* 802.11 specific flags */ 594e60c4fc2SAdrian Chadd sc->sc_rx_th.wr_chan_flags &= ~CHAN_HT; 59555caa1dfSAdrian Chadd if (rs->rs_status & HAL_RXERR_PHY) { 59655caa1dfSAdrian Chadd /* 59755caa1dfSAdrian Chadd * PHY error - make sure the channel flags 59855caa1dfSAdrian Chadd * reflect the actual channel configuration, 59955caa1dfSAdrian Chadd * not the received frame. 60055caa1dfSAdrian Chadd */ 601b8f355bfSAdrian Chadd if (IEEE80211_IS_CHAN_HT40U(sc->sc_curchan)) 60255caa1dfSAdrian Chadd sc->sc_rx_th.wr_chan_flags |= CHAN_HT40U; 603b8f355bfSAdrian Chadd else if (IEEE80211_IS_CHAN_HT40D(sc->sc_curchan)) 60455caa1dfSAdrian Chadd sc->sc_rx_th.wr_chan_flags |= CHAN_HT40D; 605b8f355bfSAdrian Chadd else if (IEEE80211_IS_CHAN_HT20(sc->sc_curchan)) 60655caa1dfSAdrian Chadd sc->sc_rx_th.wr_chan_flags |= CHAN_HT20; 60755caa1dfSAdrian Chadd } else if (sc->sc_rx_th.wr_rate & IEEE80211_RATE_MCS) { /* HT rate */ 6087a79cebfSGleb Smirnoff struct ieee80211com *ic = &sc->sc_ic; 609e60c4fc2SAdrian Chadd 610e60c4fc2SAdrian Chadd if ((rs->rs_flags & HAL_RX_2040) == 0) 611e60c4fc2SAdrian Chadd sc->sc_rx_th.wr_chan_flags |= CHAN_HT20; 612e60c4fc2SAdrian Chadd else if (IEEE80211_IS_CHAN_HT40U(ic->ic_curchan)) 613e60c4fc2SAdrian Chadd sc->sc_rx_th.wr_chan_flags |= CHAN_HT40U; 614e60c4fc2SAdrian Chadd else 615e60c4fc2SAdrian Chadd sc->sc_rx_th.wr_chan_flags |= CHAN_HT40D; 6167b6899bfSAdrian Chadd 6177b6899bfSAdrian Chadd if (rs->rs_flags & HAL_RX_GI) 618e60c4fc2SAdrian Chadd sc->sc_rx_th.wr_flags |= IEEE80211_RADIOTAP_F_SHORTGI; 619e60c4fc2SAdrian Chadd } 62055caa1dfSAdrian Chadd 621e60c4fc2SAdrian Chadd sc->sc_rx_th.wr_tsf = htole64(ath_extend_tsf(sc, rs->rs_tstamp, tsf)); 622e60c4fc2SAdrian Chadd if (rs->rs_status & HAL_RXERR_CRC) 623e60c4fc2SAdrian Chadd sc->sc_rx_th.wr_flags |= IEEE80211_RADIOTAP_F_BADFCS; 624e60c4fc2SAdrian Chadd /* XXX propagate other error flags from descriptor */ 625e60c4fc2SAdrian Chadd sc->sc_rx_th.wr_antnoise = nf; 626e60c4fc2SAdrian Chadd sc->sc_rx_th.wr_antsignal = nf + rs->rs_rssi; 627e60c4fc2SAdrian Chadd sc->sc_rx_th.wr_antenna = rs->rs_antenna; 628e60c4fc2SAdrian Chadd #undef CHAN_HT 629e60c4fc2SAdrian Chadd #undef CHAN_HT20 630e60c4fc2SAdrian Chadd #undef CHAN_HT40U 631e60c4fc2SAdrian Chadd #undef CHAN_HT40D 632e60c4fc2SAdrian Chadd } 633e60c4fc2SAdrian Chadd 634e60c4fc2SAdrian Chadd static void 635e60c4fc2SAdrian Chadd ath_handle_micerror(struct ieee80211com *ic, 636e60c4fc2SAdrian Chadd struct ieee80211_frame *wh, int keyix) 637e60c4fc2SAdrian Chadd { 638e60c4fc2SAdrian Chadd struct ieee80211_node *ni; 639e60c4fc2SAdrian Chadd 640e60c4fc2SAdrian Chadd /* XXX recheck MIC to deal w/ chips that lie */ 641e60c4fc2SAdrian Chadd /* XXX discard MIC errors on !data frames */ 642e60c4fc2SAdrian Chadd ni = ieee80211_find_rxnode(ic, (const struct ieee80211_frame_min *) wh); 643e60c4fc2SAdrian Chadd if (ni != NULL) { 644e60c4fc2SAdrian Chadd ieee80211_notify_michael_failure(ni->ni_vap, wh, keyix); 645e60c4fc2SAdrian Chadd ieee80211_free_node(ni); 646e60c4fc2SAdrian Chadd } 647e60c4fc2SAdrian Chadd } 648e60c4fc2SAdrian Chadd 6498cc724d9SAdrian Chadd /* 6508cc724d9SAdrian Chadd * Process a single packet. 6518cc724d9SAdrian Chadd * 6528cc724d9SAdrian Chadd * The mbuf must already be synced, unmapped and removed from bf->bf_m 6538cc724d9SAdrian Chadd * by this stage. 6548cc724d9SAdrian Chadd * 6558cc724d9SAdrian Chadd * The mbuf must be consumed by this routine - either passed up the 6568cc724d9SAdrian Chadd * net80211 stack, put on the holding queue, or freed. 6578cc724d9SAdrian Chadd */ 658d434a377SAdrian Chadd int 659d542f7f6SAdrian Chadd ath_rx_pkt(struct ath_softc *sc, struct ath_rx_status *rs, HAL_STATUS status, 6608cc724d9SAdrian Chadd uint64_t tsf, int nf, HAL_RX_QUEUE qtype, struct ath_buf *bf, 6618cc724d9SAdrian Chadd struct mbuf *m) 662e60c4fc2SAdrian Chadd { 663d542f7f6SAdrian Chadd uint64_t rstamp; 6640cbe6805SAdrian Chadd /* XXX TODO: make this an mbuf tag? */ 6650cbe6805SAdrian Chadd struct ieee80211_rx_stats rxs; 6660cbe6805SAdrian Chadd int len, type, i; 6677a79cebfSGleb Smirnoff struct ieee80211com *ic = &sc->sc_ic; 668e60c4fc2SAdrian Chadd struct ieee80211_node *ni; 669d542f7f6SAdrian Chadd int is_good = 0; 670d434a377SAdrian Chadd struct ath_rx_edma *re = &sc->sc_rxedma[qtype]; 671e60c4fc2SAdrian Chadd 672af2441fbSAdrian Chadd NET_EPOCH_ASSERT(); 673af2441fbSAdrian Chadd 674e60c4fc2SAdrian Chadd /* 675e60c4fc2SAdrian Chadd * Calculate the correct 64 bit TSF given 676e60c4fc2SAdrian Chadd * the TSF64 register value and rs_tstamp. 677e60c4fc2SAdrian Chadd */ 678e60c4fc2SAdrian Chadd rstamp = ath_extend_tsf(sc, rs->rs_tstamp, tsf); 679e60c4fc2SAdrian Chadd 680f46839b9SAdrian Chadd /* 802.11 return codes - These aren't specifically errors */ 681e60c4fc2SAdrian Chadd if (rs->rs_flags & HAL_RX_GI) 682e60c4fc2SAdrian Chadd sc->sc_stats.ast_rx_halfgi++; 683e60c4fc2SAdrian Chadd if (rs->rs_flags & HAL_RX_2040) 684e60c4fc2SAdrian Chadd sc->sc_stats.ast_rx_2040++; 685e60c4fc2SAdrian Chadd if (rs->rs_flags & HAL_RX_DELIM_CRC_PRE) 686e60c4fc2SAdrian Chadd sc->sc_stats.ast_rx_pre_crc_err++; 687e60c4fc2SAdrian Chadd if (rs->rs_flags & HAL_RX_DELIM_CRC_POST) 688e60c4fc2SAdrian Chadd sc->sc_stats.ast_rx_post_crc_err++; 689e60c4fc2SAdrian Chadd if (rs->rs_flags & HAL_RX_DECRYPT_BUSY) 690e60c4fc2SAdrian Chadd sc->sc_stats.ast_rx_decrypt_busy_err++; 691e60c4fc2SAdrian Chadd if (rs->rs_flags & HAL_RX_HI_RX_CHAIN) 692e60c4fc2SAdrian Chadd sc->sc_stats.ast_rx_hi_rx_chain++; 6932c47932cSAdrian Chadd if (rs->rs_flags & HAL_RX_STBC) 6942c47932cSAdrian Chadd sc->sc_stats.ast_rx_stbc++; 695e60c4fc2SAdrian Chadd 696e60c4fc2SAdrian Chadd if (rs->rs_status != 0) { 697e60c4fc2SAdrian Chadd if (rs->rs_status & HAL_RXERR_CRC) 698e60c4fc2SAdrian Chadd sc->sc_stats.ast_rx_crcerr++; 699e60c4fc2SAdrian Chadd if (rs->rs_status & HAL_RXERR_FIFO) 700e60c4fc2SAdrian Chadd sc->sc_stats.ast_rx_fifoerr++; 701e60c4fc2SAdrian Chadd if (rs->rs_status & HAL_RXERR_PHY) { 702e60c4fc2SAdrian Chadd sc->sc_stats.ast_rx_phyerr++; 703e60c4fc2SAdrian Chadd /* Process DFS radar events */ 704e60c4fc2SAdrian Chadd if ((rs->rs_phyerr == HAL_PHYERR_RADAR) || 705e60c4fc2SAdrian Chadd (rs->rs_phyerr == HAL_PHYERR_FALSE_RADAR_EXT)) { 706e60c4fc2SAdrian Chadd /* Now pass it to the radar processing code */ 707d77363adSAdrian Chadd ath_dfs_process_phy_err(sc, m, rstamp, rs); 708e60c4fc2SAdrian Chadd } 709e60c4fc2SAdrian Chadd 71068545bc4SAdrian Chadd /* 71168545bc4SAdrian Chadd * Be suitably paranoid about receiving phy errors 71268545bc4SAdrian Chadd * out of the stats array bounds 71368545bc4SAdrian Chadd */ 71468545bc4SAdrian Chadd if (rs->rs_phyerr < ATH_IOCTL_STATS_NUM_RX_PHYERR) 715e60c4fc2SAdrian Chadd sc->sc_stats.ast_rx_phy[rs->rs_phyerr]++; 716e60c4fc2SAdrian Chadd goto rx_error; /* NB: don't count in ierrors */ 717e60c4fc2SAdrian Chadd } 718e60c4fc2SAdrian Chadd if (rs->rs_status & HAL_RXERR_DECRYPT) { 719e60c4fc2SAdrian Chadd /* 720e60c4fc2SAdrian Chadd * Decrypt error. If the error occurred 721e60c4fc2SAdrian Chadd * because there was no hardware key, then 722e60c4fc2SAdrian Chadd * let the frame through so the upper layers 723e60c4fc2SAdrian Chadd * can process it. This is necessary for 5210 724e60c4fc2SAdrian Chadd * parts which have no way to setup a ``clear'' 725e60c4fc2SAdrian Chadd * key cache entry. 726e60c4fc2SAdrian Chadd * 727e60c4fc2SAdrian Chadd * XXX do key cache faulting 728e60c4fc2SAdrian Chadd */ 729e60c4fc2SAdrian Chadd if (rs->rs_keyix == HAL_RXKEYIX_INVALID) 730e60c4fc2SAdrian Chadd goto rx_accept; 731e60c4fc2SAdrian Chadd sc->sc_stats.ast_rx_badcrypt++; 732e60c4fc2SAdrian Chadd } 733c7f5bb7aSAdrian Chadd /* 734c7f5bb7aSAdrian Chadd * Similar as above - if the failure was a keymiss 735c7f5bb7aSAdrian Chadd * just punt it up to the upper layers for now. 736c7f5bb7aSAdrian Chadd */ 737c7f5bb7aSAdrian Chadd if (rs->rs_status & HAL_RXERR_KEYMISS) { 738c7f5bb7aSAdrian Chadd sc->sc_stats.ast_rx_keymiss++; 739c7f5bb7aSAdrian Chadd goto rx_accept; 740c7f5bb7aSAdrian Chadd } 741e60c4fc2SAdrian Chadd if (rs->rs_status & HAL_RXERR_MIC) { 742e60c4fc2SAdrian Chadd sc->sc_stats.ast_rx_badmic++; 743e60c4fc2SAdrian Chadd /* 744e60c4fc2SAdrian Chadd * Do minimal work required to hand off 745e60c4fc2SAdrian Chadd * the 802.11 header for notification. 746e60c4fc2SAdrian Chadd */ 747e60c4fc2SAdrian Chadd /* XXX frag's and qos frames */ 748e60c4fc2SAdrian Chadd len = rs->rs_datalen; 749e60c4fc2SAdrian Chadd if (len >= sizeof (struct ieee80211_frame)) { 750e60c4fc2SAdrian Chadd ath_handle_micerror(ic, 751e60c4fc2SAdrian Chadd mtod(m, struct ieee80211_frame *), 752e60c4fc2SAdrian Chadd sc->sc_splitmic ? 753e60c4fc2SAdrian Chadd rs->rs_keyix-32 : rs->rs_keyix); 754e60c4fc2SAdrian Chadd } 755e60c4fc2SAdrian Chadd } 7567a79cebfSGleb Smirnoff counter_u64_add(ic->ic_ierrors, 1); 757e60c4fc2SAdrian Chadd rx_error: 758e60c4fc2SAdrian Chadd /* 759e60c4fc2SAdrian Chadd * Cleanup any pending partial frame. 760e60c4fc2SAdrian Chadd */ 761d434a377SAdrian Chadd if (re->m_rxpending != NULL) { 762d434a377SAdrian Chadd m_freem(re->m_rxpending); 763d434a377SAdrian Chadd re->m_rxpending = NULL; 764e60c4fc2SAdrian Chadd } 765e60c4fc2SAdrian Chadd /* 766e60c4fc2SAdrian Chadd * When a tap is present pass error frames 767e60c4fc2SAdrian Chadd * that have been requested. By default we 768e60c4fc2SAdrian Chadd * pass decrypt+mic errors but others may be 769e60c4fc2SAdrian Chadd * interesting (e.g. crc). 770e60c4fc2SAdrian Chadd */ 771e60c4fc2SAdrian Chadd if (ieee80211_radiotap_active(ic) && 772e60c4fc2SAdrian Chadd (rs->rs_status & sc->sc_monpass)) { 773e60c4fc2SAdrian Chadd /* NB: bpf needs the mbuf length setup */ 774e60c4fc2SAdrian Chadd len = rs->rs_datalen; 775e60c4fc2SAdrian Chadd m->m_pkthdr.len = m->m_len = len; 7767a79cebfSGleb Smirnoff ath_rx_tap(sc, m, rs, rstamp, nf); 777e1b5ab97SAdrian Chadd #ifdef ATH_ENABLE_RADIOTAP_VENDOR_EXT 7787a79cebfSGleb Smirnoff ath_rx_tap_vendor(sc, m, rs, rstamp, nf); 779e1b5ab97SAdrian Chadd #endif /* ATH_ENABLE_RADIOTAP_VENDOR_EXT */ 780e60c4fc2SAdrian Chadd ieee80211_radiotap_rx_all(ic, m); 781e60c4fc2SAdrian Chadd } 782e60c4fc2SAdrian Chadd /* XXX pass MIC errors up for s/w reclaculation */ 7838cc724d9SAdrian Chadd m_freem(m); m = NULL; 784e60c4fc2SAdrian Chadd goto rx_next; 785e60c4fc2SAdrian Chadd } 786e60c4fc2SAdrian Chadd rx_accept: 787e60c4fc2SAdrian Chadd len = rs->rs_datalen; 788e60c4fc2SAdrian Chadd m->m_len = len; 789e60c4fc2SAdrian Chadd 790e60c4fc2SAdrian Chadd if (rs->rs_more) { 791e60c4fc2SAdrian Chadd /* 792e60c4fc2SAdrian Chadd * Frame spans multiple descriptors; save 793e60c4fc2SAdrian Chadd * it for the next completed descriptor, it 794e60c4fc2SAdrian Chadd * will be used to construct a jumbogram. 795e60c4fc2SAdrian Chadd */ 796d434a377SAdrian Chadd if (re->m_rxpending != NULL) { 797e60c4fc2SAdrian Chadd /* NB: max frame size is currently 2 clusters */ 798e60c4fc2SAdrian Chadd sc->sc_stats.ast_rx_toobig++; 799d434a377SAdrian Chadd m_freem(re->m_rxpending); 800e60c4fc2SAdrian Chadd } 801e60c4fc2SAdrian Chadd m->m_pkthdr.len = len; 802d434a377SAdrian Chadd re->m_rxpending = m; 8038cc724d9SAdrian Chadd m = NULL; 804e60c4fc2SAdrian Chadd goto rx_next; 805d434a377SAdrian Chadd } else if (re->m_rxpending != NULL) { 806e60c4fc2SAdrian Chadd /* 807e60c4fc2SAdrian Chadd * This is the second part of a jumbogram, 808e60c4fc2SAdrian Chadd * chain it to the first mbuf, adjust the 809e60c4fc2SAdrian Chadd * frame length, and clear the rxpending state. 810e60c4fc2SAdrian Chadd */ 811d434a377SAdrian Chadd re->m_rxpending->m_next = m; 812d434a377SAdrian Chadd re->m_rxpending->m_pkthdr.len += len; 813d434a377SAdrian Chadd m = re->m_rxpending; 814d434a377SAdrian Chadd re->m_rxpending = NULL; 815e60c4fc2SAdrian Chadd } else { 816e60c4fc2SAdrian Chadd /* 8177a79cebfSGleb Smirnoff * Normal single-descriptor receive; setup packet length. 818e60c4fc2SAdrian Chadd */ 819e60c4fc2SAdrian Chadd m->m_pkthdr.len = len; 820e60c4fc2SAdrian Chadd } 821e60c4fc2SAdrian Chadd 822e60c4fc2SAdrian Chadd /* 823e60c4fc2SAdrian Chadd * Validate rs->rs_antenna. 824e60c4fc2SAdrian Chadd * 825e60c4fc2SAdrian Chadd * Some users w/ AR9285 NICs have reported crashes 826e60c4fc2SAdrian Chadd * here because rs_antenna field is bogusly large. 827e60c4fc2SAdrian Chadd * Let's enforce the maximum antenna limit of 8 828e60c4fc2SAdrian Chadd * (and it shouldn't be hard coded, but that's a 829e60c4fc2SAdrian Chadd * separate problem) and if there's an issue, print 830e60c4fc2SAdrian Chadd * out an error and adjust rs_antenna to something 831e60c4fc2SAdrian Chadd * sensible. 832e60c4fc2SAdrian Chadd * 833e60c4fc2SAdrian Chadd * This code should be removed once the actual 834e60c4fc2SAdrian Chadd * root cause of the issue has been identified. 835e60c4fc2SAdrian Chadd * For example, it may be that the rs_antenna 836f6b6084bSPedro F. Giffuni * field is only valid for the last frame of 837e60c4fc2SAdrian Chadd * an aggregate and it just happens that it is 838e60c4fc2SAdrian Chadd * "mostly" right. (This is a general statement - 839e60c4fc2SAdrian Chadd * the majority of the statistics are only valid 840e60c4fc2SAdrian Chadd * for the last frame in an aggregate. 841e60c4fc2SAdrian Chadd */ 84268545bc4SAdrian Chadd if (rs->rs_antenna >= ATH_IOCTL_STATS_NUM_RX_ANTENNA) { 843e60c4fc2SAdrian Chadd device_printf(sc->sc_dev, "%s: rs_antenna > 7 (%d)\n", 844e60c4fc2SAdrian Chadd __func__, rs->rs_antenna); 845e60c4fc2SAdrian Chadd #ifdef ATH_DEBUG 846e60c4fc2SAdrian Chadd ath_printrxbuf(sc, bf, 0, status == HAL_OK); 847e60c4fc2SAdrian Chadd #endif /* ATH_DEBUG */ 848e60c4fc2SAdrian Chadd rs->rs_antenna = 0; /* XXX better than nothing */ 849e60c4fc2SAdrian Chadd } 850e60c4fc2SAdrian Chadd 8513df7a8abSAdrian Chadd /* 8523df7a8abSAdrian Chadd * If this is an AR9285/AR9485, then the receive and LNA 8533df7a8abSAdrian Chadd * configuration is stored in RSSI[2] / EXTRSSI[2]. 8543df7a8abSAdrian Chadd * We can extract this out to build a much better 8553df7a8abSAdrian Chadd * receive antenna profile. 8563df7a8abSAdrian Chadd * 8573df7a8abSAdrian Chadd * Yes, this just blurts over the above RX antenna field 8583df7a8abSAdrian Chadd * for now. It's fine, the AR9285 doesn't really use 8593df7a8abSAdrian Chadd * that. 8603df7a8abSAdrian Chadd * 8613df7a8abSAdrian Chadd * Later on we should store away the fine grained LNA 8623df7a8abSAdrian Chadd * information and keep separate counters just for 8633df7a8abSAdrian Chadd * that. It'll help when debugging the AR9285/AR9485 8643df7a8abSAdrian Chadd * combined diversity code. 8653df7a8abSAdrian Chadd */ 8663df7a8abSAdrian Chadd if (sc->sc_rx_lnamixer) { 8673df7a8abSAdrian Chadd rs->rs_antenna = 0; 8683df7a8abSAdrian Chadd 8693df7a8abSAdrian Chadd /* Bits 0:1 - the LNA configuration used */ 8703df7a8abSAdrian Chadd rs->rs_antenna |= 8713df7a8abSAdrian Chadd ((rs->rs_rssi_ctl[2] & HAL_RX_LNA_CFG_USED) 8723df7a8abSAdrian Chadd >> HAL_RX_LNA_CFG_USED_S); 8733df7a8abSAdrian Chadd 8743df7a8abSAdrian Chadd /* Bit 2 - the external RX antenna switch */ 8753df7a8abSAdrian Chadd if (rs->rs_rssi_ctl[2] & HAL_RX_LNA_EXTCFG) 8763df7a8abSAdrian Chadd rs->rs_antenna |= 0x4; 8773df7a8abSAdrian Chadd } 8783df7a8abSAdrian Chadd 879e60c4fc2SAdrian Chadd sc->sc_stats.ast_ant_rx[rs->rs_antenna]++; 880e60c4fc2SAdrian Chadd 881e60c4fc2SAdrian Chadd /* 882e60c4fc2SAdrian Chadd * Populate the rx status block. When there are bpf 883e60c4fc2SAdrian Chadd * listeners we do the additional work to provide 884e60c4fc2SAdrian Chadd * complete status. Otherwise we fill in only the 885e60c4fc2SAdrian Chadd * material required by ieee80211_input. Note that 886e60c4fc2SAdrian Chadd * noise setting is filled in above. 887e60c4fc2SAdrian Chadd */ 888e1b5ab97SAdrian Chadd if (ieee80211_radiotap_active(ic)) { 8897a79cebfSGleb Smirnoff ath_rx_tap(sc, m, rs, rstamp, nf); 890e1b5ab97SAdrian Chadd #ifdef ATH_ENABLE_RADIOTAP_VENDOR_EXT 8917a79cebfSGleb Smirnoff ath_rx_tap_vendor(sc, m, rs, rstamp, nf); 892e1b5ab97SAdrian Chadd #endif /* ATH_ENABLE_RADIOTAP_VENDOR_EXT */ 893e1b5ab97SAdrian Chadd } 894e60c4fc2SAdrian Chadd 895e60c4fc2SAdrian Chadd /* 896e60c4fc2SAdrian Chadd * From this point on we assume the frame is at least 897e60c4fc2SAdrian Chadd * as large as ieee80211_frame_min; verify that. 898e60c4fc2SAdrian Chadd */ 899e60c4fc2SAdrian Chadd if (len < IEEE80211_MIN_LEN) { 900e60c4fc2SAdrian Chadd if (!ieee80211_radiotap_active(ic)) { 901e60c4fc2SAdrian Chadd DPRINTF(sc, ATH_DEBUG_RECV, 902e60c4fc2SAdrian Chadd "%s: short packet %d\n", __func__, len); 903e60c4fc2SAdrian Chadd sc->sc_stats.ast_rx_tooshort++; 904e60c4fc2SAdrian Chadd } else { 905e60c4fc2SAdrian Chadd /* NB: in particular this captures ack's */ 906e60c4fc2SAdrian Chadd ieee80211_radiotap_rx_all(ic, m); 907e60c4fc2SAdrian Chadd } 9088cc724d9SAdrian Chadd m_freem(m); m = NULL; 909e60c4fc2SAdrian Chadd goto rx_next; 910e60c4fc2SAdrian Chadd } 911e60c4fc2SAdrian Chadd 912e60c4fc2SAdrian Chadd if (IFF_DUMPPKTS(sc, ATH_DEBUG_RECV)) { 913e60c4fc2SAdrian Chadd const HAL_RATE_TABLE *rt = sc->sc_currates; 914e60c4fc2SAdrian Chadd uint8_t rix = rt->rateCodeToIndex[rs->rs_rate]; 915e60c4fc2SAdrian Chadd 916e60c4fc2SAdrian Chadd ieee80211_dump_pkt(ic, mtod(m, caddr_t), len, 917e60c4fc2SAdrian Chadd sc->sc_hwmap[rix].ieeerate, rs->rs_rssi); 918e60c4fc2SAdrian Chadd } 919e60c4fc2SAdrian Chadd 920e60c4fc2SAdrian Chadd m_adj(m, -IEEE80211_CRC_LEN); 921e60c4fc2SAdrian Chadd 922e60c4fc2SAdrian Chadd /* 923e60c4fc2SAdrian Chadd * Locate the node for sender, track state, and then 924e60c4fc2SAdrian Chadd * pass the (referenced) node up to the 802.11 layer 925e60c4fc2SAdrian Chadd * for its use. 926e60c4fc2SAdrian Chadd */ 927e60c4fc2SAdrian Chadd ni = ieee80211_find_rxnode_withkey(ic, 928e60c4fc2SAdrian Chadd mtod(m, const struct ieee80211_frame_min *), 929e60c4fc2SAdrian Chadd rs->rs_keyix == HAL_RXKEYIX_INVALID ? 930e60c4fc2SAdrian Chadd IEEE80211_KEYIX_NONE : rs->rs_keyix); 931e60c4fc2SAdrian Chadd sc->sc_lastrs = rs; 932e60c4fc2SAdrian Chadd 933e60c4fc2SAdrian Chadd if (rs->rs_isaggr) 934e60c4fc2SAdrian Chadd sc->sc_stats.ast_rx_agg++; 9350cbe6805SAdrian Chadd 9360cbe6805SAdrian Chadd /* 9370cbe6805SAdrian Chadd * Populate the per-chain RSSI values where appropriate. 9380cbe6805SAdrian Chadd */ 9390cbe6805SAdrian Chadd bzero(&rxs, sizeof(rxs)); 9400cbe6805SAdrian Chadd rxs.r_flags |= IEEE80211_R_NF | IEEE80211_R_RSSI | 9410cbe6805SAdrian Chadd IEEE80211_R_C_CHAIN | 9420cbe6805SAdrian Chadd IEEE80211_R_C_NF | 9430cbe6805SAdrian Chadd IEEE80211_R_C_RSSI | 9440cbe6805SAdrian Chadd IEEE80211_R_TSF64 | 9450cbe6805SAdrian Chadd IEEE80211_R_TSF_START; /* XXX TODO: validate */ 9460cbe6805SAdrian Chadd rxs.c_rssi = rs->rs_rssi; 9470cbe6805SAdrian Chadd rxs.c_nf = nf; 9480cbe6805SAdrian Chadd rxs.c_chain = 3; /* XXX TODO: check */ 9490cbe6805SAdrian Chadd rxs.c_rx_tsf = rstamp; 9500cbe6805SAdrian Chadd 9510cbe6805SAdrian Chadd for (i = 0; i < 3; i++) { 9520cbe6805SAdrian Chadd rxs.c_rssi_ctl[i] = rs->rs_rssi_ctl[i]; 9530cbe6805SAdrian Chadd rxs.c_rssi_ext[i] = rs->rs_rssi_ext[i]; 9540cbe6805SAdrian Chadd /* 9550cbe6805SAdrian Chadd * XXX note: we currently don't track 9560cbe6805SAdrian Chadd * per-chain noisefloor. 9570cbe6805SAdrian Chadd */ 9580cbe6805SAdrian Chadd rxs.c_nf_ctl[i] = nf; 9590cbe6805SAdrian Chadd rxs.c_nf_ext[i] = nf; 9600cbe6805SAdrian Chadd } 9610cbe6805SAdrian Chadd 962e60c4fc2SAdrian Chadd if (ni != NULL) { 963e60c4fc2SAdrian Chadd /* 964e60c4fc2SAdrian Chadd * Only punt packets for ampdu reorder processing for 965e60c4fc2SAdrian Chadd * 11n nodes; net80211 enforces that M_AMPDU is only 966e60c4fc2SAdrian Chadd * set for 11n nodes. 967e60c4fc2SAdrian Chadd */ 968e60c4fc2SAdrian Chadd if (ni->ni_flags & IEEE80211_NODE_HT) 969e60c4fc2SAdrian Chadd m->m_flags |= M_AMPDU; 970e60c4fc2SAdrian Chadd 971e60c4fc2SAdrian Chadd /* 9727d450faaSAdrian Chadd * Inform rate control about the received RSSI. 9737d450faaSAdrian Chadd * It can then use this information to potentially drastically 9747d450faaSAdrian Chadd * alter the available rate based on the RSSI estimate. 9757d450faaSAdrian Chadd * 9767d450faaSAdrian Chadd * This is super important when associating to a far away station; 9777d450faaSAdrian Chadd * you don't want to waste time trying higher rates at some low 9787d450faaSAdrian Chadd * packet exchange rate (like during DHCP) just to establish 9797d450faaSAdrian Chadd * that higher MCS rates aren't available. 9807d450faaSAdrian Chadd */ 9817d450faaSAdrian Chadd ATH_RSSI_LPF(ATH_NODE(ni)->an_node_stats.ns_avgrssi, 9827d450faaSAdrian Chadd rs->rs_rssi); 9837d450faaSAdrian Chadd ath_rate_update_rx_rssi(sc, ATH_NODE(ni), 9847d450faaSAdrian Chadd ATH_RSSI(ATH_NODE(ni)->an_node_stats.ns_avgrssi)); 9857d450faaSAdrian Chadd 9867d450faaSAdrian Chadd /* 987e60c4fc2SAdrian Chadd * Sending station is known, dispatch directly. 988e60c4fc2SAdrian Chadd */ 9890cbe6805SAdrian Chadd (void) ieee80211_add_rx_params(m, &rxs); 9900cbe6805SAdrian Chadd type = ieee80211_input_mimo(ni, m); 991e60c4fc2SAdrian Chadd ieee80211_free_node(ni); 9928cc724d9SAdrian Chadd m = NULL; 993e60c4fc2SAdrian Chadd /* 994e60c4fc2SAdrian Chadd * Arrange to update the last rx timestamp only for 995e60c4fc2SAdrian Chadd * frames from our ap when operating in station mode. 996e60c4fc2SAdrian Chadd * This assumes the rx key is always setup when 997e60c4fc2SAdrian Chadd * associated. 998e60c4fc2SAdrian Chadd */ 999e60c4fc2SAdrian Chadd if (ic->ic_opmode == IEEE80211_M_STA && 1000e60c4fc2SAdrian Chadd rs->rs_keyix != HAL_RXKEYIX_INVALID) 1001d542f7f6SAdrian Chadd is_good = 1; 1002e60c4fc2SAdrian Chadd } else { 10030cbe6805SAdrian Chadd (void) ieee80211_add_rx_params(m, &rxs); 10040cbe6805SAdrian Chadd type = ieee80211_input_mimo_all(ic, m); 10058cc724d9SAdrian Chadd m = NULL; 1006e60c4fc2SAdrian Chadd } 10078cc724d9SAdrian Chadd 10088cc724d9SAdrian Chadd /* 10098cc724d9SAdrian Chadd * At this point we have passed the frame up the stack; thus 10108cc724d9SAdrian Chadd * the mbuf is no longer ours. 10118cc724d9SAdrian Chadd */ 10128cc724d9SAdrian Chadd 1013e60c4fc2SAdrian Chadd /* 10147d450faaSAdrian Chadd * Track legacy station RX rssi and do any rx antenna management. 1015e60c4fc2SAdrian Chadd */ 1016e60c4fc2SAdrian Chadd ATH_RSSI_LPF(sc->sc_halstats.ns_avgrssi, rs->rs_rssi); 1017e60c4fc2SAdrian Chadd if (sc->sc_diversity) { 1018e60c4fc2SAdrian Chadd /* 1019e60c4fc2SAdrian Chadd * When using fast diversity, change the default rx 1020e60c4fc2SAdrian Chadd * antenna if diversity chooses the other antenna 3 1021e60c4fc2SAdrian Chadd * times in a row. 1022e60c4fc2SAdrian Chadd */ 1023e60c4fc2SAdrian Chadd if (sc->sc_defant != rs->rs_antenna) { 1024e60c4fc2SAdrian Chadd if (++sc->sc_rxotherant >= 3) 1025e60c4fc2SAdrian Chadd ath_setdefantenna(sc, rs->rs_antenna); 1026e60c4fc2SAdrian Chadd } else 1027e60c4fc2SAdrian Chadd sc->sc_rxotherant = 0; 1028e60c4fc2SAdrian Chadd } 1029e60c4fc2SAdrian Chadd 1030216ca234SAdrian Chadd /* Handle slow diversity if enabled */ 1031216ca234SAdrian Chadd if (sc->sc_dolnadiv) { 1032216ca234SAdrian Chadd ath_lna_rx_comb_scan(sc, rs, ticks, hz); 1033216ca234SAdrian Chadd } 1034e60c4fc2SAdrian Chadd 1035e60c4fc2SAdrian Chadd if (sc->sc_softled) { 1036e60c4fc2SAdrian Chadd /* 1037e60c4fc2SAdrian Chadd * Blink for any data frame. Otherwise do a 1038e60c4fc2SAdrian Chadd * heartbeat-style blink when idle. The latter 1039e60c4fc2SAdrian Chadd * is mainly for station mode where we depend on 1040e60c4fc2SAdrian Chadd * periodic beacon frames to trigger the poll event. 1041e60c4fc2SAdrian Chadd */ 1042e60c4fc2SAdrian Chadd if (type == IEEE80211_FC0_TYPE_DATA) { 1043e60c4fc2SAdrian Chadd const HAL_RATE_TABLE *rt = sc->sc_currates; 1044e60c4fc2SAdrian Chadd ath_led_event(sc, 1045e60c4fc2SAdrian Chadd rt->rateCodeToIndex[rs->rs_rate]); 1046e60c4fc2SAdrian Chadd } else if (ticks - sc->sc_ledevent >= sc->sc_ledidle) 1047e60c4fc2SAdrian Chadd ath_led_event(sc, 0); 1048e60c4fc2SAdrian Chadd } 1049e60c4fc2SAdrian Chadd rx_next: 10508cc724d9SAdrian Chadd /* 10518cc724d9SAdrian Chadd * Debugging - complain if we didn't NULL the mbuf pointer 10528cc724d9SAdrian Chadd * here. 10538cc724d9SAdrian Chadd */ 10548cc724d9SAdrian Chadd if (m != NULL) { 10558cc724d9SAdrian Chadd device_printf(sc->sc_dev, 10568cc724d9SAdrian Chadd "%s: mbuf %p should've been freed!\n", 10578cc724d9SAdrian Chadd __func__, 10588cc724d9SAdrian Chadd m); 10598cc724d9SAdrian Chadd } 1060d542f7f6SAdrian Chadd return (is_good); 1061d542f7f6SAdrian Chadd } 1062d542f7f6SAdrian Chadd 1063516f6796SAdrian Chadd #define ATH_RX_MAX 128 1064516f6796SAdrian Chadd 106567aaf739SAdrian Chadd /* 106667aaf739SAdrian Chadd * XXX TODO: break out the "get buffers" from "call ath_rx_pkt()" like 106767aaf739SAdrian Chadd * the EDMA code does. 106867aaf739SAdrian Chadd * 106967aaf739SAdrian Chadd * XXX TODO: then, do all of the RX list management stuff inside 107067aaf739SAdrian Chadd * ATH_RX_LOCK() so we don't end up potentially racing. The EDMA 107167aaf739SAdrian Chadd * code is doing it right. 107267aaf739SAdrian Chadd */ 1073f8cc9b09SAdrian Chadd static void 1074d542f7f6SAdrian Chadd ath_rx_proc(struct ath_softc *sc, int resched) 1075d542f7f6SAdrian Chadd { 1076d542f7f6SAdrian Chadd #define PA2DESC(_sc, _pa) \ 1077d542f7f6SAdrian Chadd ((struct ath_desc *)((caddr_t)(_sc)->sc_rxdma.dd_desc + \ 1078d542f7f6SAdrian Chadd ((_pa) - (_sc)->sc_rxdma.dd_desc_paddr))) 1079d542f7f6SAdrian Chadd struct ath_buf *bf; 1080d542f7f6SAdrian Chadd struct ath_hal *ah = sc->sc_ah; 1081803f0c59SAdrian Chadd #ifdef IEEE80211_SUPPORT_SUPERG 10827a79cebfSGleb Smirnoff struct ieee80211com *ic = &sc->sc_ic; 1083803f0c59SAdrian Chadd #endif 1084d542f7f6SAdrian Chadd struct ath_desc *ds; 1085d542f7f6SAdrian Chadd struct ath_rx_status *rs; 1086d542f7f6SAdrian Chadd struct mbuf *m; 1087d542f7f6SAdrian Chadd int ngood; 1088d542f7f6SAdrian Chadd HAL_STATUS status; 1089d542f7f6SAdrian Chadd int16_t nf; 1090d542f7f6SAdrian Chadd u_int64_t tsf; 1091d542f7f6SAdrian Chadd int npkts = 0; 1092233af52dSAdrian Chadd int kickpcu = 0; 109367aaf739SAdrian Chadd int ret; 1094d542f7f6SAdrian Chadd 1095af2441fbSAdrian Chadd NET_EPOCH_ASSERT(); 1096af2441fbSAdrian Chadd 1097d542f7f6SAdrian Chadd /* XXX we must not hold the ATH_LOCK here */ 1098d542f7f6SAdrian Chadd ATH_UNLOCK_ASSERT(sc); 1099d542f7f6SAdrian Chadd ATH_PCU_UNLOCK_ASSERT(sc); 1100d542f7f6SAdrian Chadd 1101d542f7f6SAdrian Chadd ATH_PCU_LOCK(sc); 1102d542f7f6SAdrian Chadd sc->sc_rxproc_cnt++; 1103233af52dSAdrian Chadd kickpcu = sc->sc_kickpcu; 1104d542f7f6SAdrian Chadd ATH_PCU_UNLOCK(sc); 1105d542f7f6SAdrian Chadd 1106f5c30c4eSAdrian Chadd ATH_LOCK(sc); 1107f5c30c4eSAdrian Chadd ath_power_set_power_state(sc, HAL_PM_AWAKE); 1108f5c30c4eSAdrian Chadd ATH_UNLOCK(sc); 1109f5c30c4eSAdrian Chadd 1110d542f7f6SAdrian Chadd DPRINTF(sc, ATH_DEBUG_RX_PROC, "%s: called\n", __func__); 1111d542f7f6SAdrian Chadd ngood = 0; 1112d542f7f6SAdrian Chadd nf = ath_hal_getchannoise(ah, sc->sc_curchan); 1113d542f7f6SAdrian Chadd sc->sc_stats.ast_rx_noise = nf; 1114d542f7f6SAdrian Chadd tsf = ath_hal_gettsf64(ah); 1115d542f7f6SAdrian Chadd do { 1116516f6796SAdrian Chadd /* 1117516f6796SAdrian Chadd * Don't process too many packets at a time; give the 1118516f6796SAdrian Chadd * TX thread time to also run - otherwise the TX 1119516f6796SAdrian Chadd * latency can jump by quite a bit, causing throughput 1120516f6796SAdrian Chadd * degredation. 1121516f6796SAdrian Chadd */ 1122233af52dSAdrian Chadd if (!kickpcu && npkts >= ATH_RX_MAX) 1123516f6796SAdrian Chadd break; 1124516f6796SAdrian Chadd 1125d542f7f6SAdrian Chadd bf = TAILQ_FIRST(&sc->sc_rxbuf); 1126d542f7f6SAdrian Chadd if (sc->sc_rxslink && bf == NULL) { /* NB: shouldn't happen */ 112776e6fd5dSGleb Smirnoff device_printf(sc->sc_dev, "%s: no buffer!\n", __func__); 1128d542f7f6SAdrian Chadd break; 1129d542f7f6SAdrian Chadd } else if (bf == NULL) { 1130d542f7f6SAdrian Chadd /* 1131d542f7f6SAdrian Chadd * End of List: 1132d542f7f6SAdrian Chadd * this can happen for non-self-linked RX chains 1133d542f7f6SAdrian Chadd */ 1134d542f7f6SAdrian Chadd sc->sc_stats.ast_rx_hitqueueend++; 1135d542f7f6SAdrian Chadd break; 1136d542f7f6SAdrian Chadd } 1137d542f7f6SAdrian Chadd m = bf->bf_m; 1138d542f7f6SAdrian Chadd if (m == NULL) { /* NB: shouldn't happen */ 1139d542f7f6SAdrian Chadd /* 1140d542f7f6SAdrian Chadd * If mbuf allocation failed previously there 1141d542f7f6SAdrian Chadd * will be no mbuf; try again to re-populate it. 1142d542f7f6SAdrian Chadd */ 1143d542f7f6SAdrian Chadd /* XXX make debug msg */ 114476e6fd5dSGleb Smirnoff device_printf(sc->sc_dev, "%s: no mbuf!\n", __func__); 1145d542f7f6SAdrian Chadd TAILQ_REMOVE(&sc->sc_rxbuf, bf, bf_list); 1146d542f7f6SAdrian Chadd goto rx_proc_next; 1147d542f7f6SAdrian Chadd } 1148d542f7f6SAdrian Chadd ds = bf->bf_desc; 1149d542f7f6SAdrian Chadd if (ds->ds_link == bf->bf_daddr) { 1150d542f7f6SAdrian Chadd /* NB: never process the self-linked entry at the end */ 1151d542f7f6SAdrian Chadd sc->sc_stats.ast_rx_hitqueueend++; 1152d542f7f6SAdrian Chadd break; 1153d542f7f6SAdrian Chadd } 1154d542f7f6SAdrian Chadd /* XXX sync descriptor memory */ 1155d542f7f6SAdrian Chadd /* 1156d542f7f6SAdrian Chadd * Must provide the virtual address of the current 1157d542f7f6SAdrian Chadd * descriptor, the physical address, and the virtual 1158d542f7f6SAdrian Chadd * address of the next descriptor in the h/w chain. 1159d542f7f6SAdrian Chadd * This allows the HAL to look ahead to see if the 1160d542f7f6SAdrian Chadd * hardware is done with a descriptor by checking the 1161d542f7f6SAdrian Chadd * done bit in the following descriptor and the address 1162d542f7f6SAdrian Chadd * of the current descriptor the DMA engine is working 1163d542f7f6SAdrian Chadd * on. All this is necessary because of our use of 1164d542f7f6SAdrian Chadd * a self-linked list to avoid rx overruns. 1165d542f7f6SAdrian Chadd */ 1166d542f7f6SAdrian Chadd rs = &bf->bf_status.ds_rxstat; 1167d542f7f6SAdrian Chadd status = ath_hal_rxprocdesc(ah, ds, 1168d542f7f6SAdrian Chadd bf->bf_daddr, PA2DESC(sc, ds->ds_link), rs); 1169d542f7f6SAdrian Chadd #ifdef ATH_DEBUG 1170d542f7f6SAdrian Chadd if (sc->sc_debug & ATH_DEBUG_RECV_DESC) 1171d542f7f6SAdrian Chadd ath_printrxbuf(sc, bf, 0, status == HAL_OK); 1172d542f7f6SAdrian Chadd #endif 1173bb327d28SAdrian Chadd 1174bb327d28SAdrian Chadd #ifdef ATH_DEBUG_ALQ 1175bb327d28SAdrian Chadd if (if_ath_alq_checkdebug(&sc->sc_alq, ATH_ALQ_EDMA_RXSTATUS)) 1176bb327d28SAdrian Chadd if_ath_alq_post(&sc->sc_alq, ATH_ALQ_EDMA_RXSTATUS, 1177bb327d28SAdrian Chadd sc->sc_rx_statuslen, (char *) ds); 1178bb327d28SAdrian Chadd #endif /* ATH_DEBUG_ALQ */ 1179bb327d28SAdrian Chadd 1180d542f7f6SAdrian Chadd if (status == HAL_EINPROGRESS) 1181d542f7f6SAdrian Chadd break; 1182d542f7f6SAdrian Chadd 1183d542f7f6SAdrian Chadd TAILQ_REMOVE(&sc->sc_rxbuf, bf, bf_list); 1184d542f7f6SAdrian Chadd npkts++; 1185d542f7f6SAdrian Chadd 1186d542f7f6SAdrian Chadd /* 1187d542f7f6SAdrian Chadd * Process a single frame. 1188d542f7f6SAdrian Chadd */ 11898cc724d9SAdrian Chadd bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap, BUS_DMASYNC_POSTREAD); 11908cc724d9SAdrian Chadd bus_dmamap_unload(sc->sc_dmat, bf->bf_dmamap); 11918cc724d9SAdrian Chadd bf->bf_m = NULL; 11928cc724d9SAdrian Chadd if (ath_rx_pkt(sc, rs, status, tsf, nf, HAL_RX_QUEUE_HP, bf, m)) 1193d542f7f6SAdrian Chadd ngood++; 1194d542f7f6SAdrian Chadd rx_proc_next: 119567aaf739SAdrian Chadd /* 119667aaf739SAdrian Chadd * If there's a holding buffer, insert that onto 119767aaf739SAdrian Chadd * the RX list; the hardware is now definitely not pointing 119867aaf739SAdrian Chadd * to it now. 119967aaf739SAdrian Chadd */ 120067aaf739SAdrian Chadd ret = 0; 120167aaf739SAdrian Chadd if (sc->sc_rxedma[HAL_RX_QUEUE_HP].m_holdbf != NULL) { 120267aaf739SAdrian Chadd TAILQ_INSERT_TAIL(&sc->sc_rxbuf, 120367aaf739SAdrian Chadd sc->sc_rxedma[HAL_RX_QUEUE_HP].m_holdbf, 120467aaf739SAdrian Chadd bf_list); 120567aaf739SAdrian Chadd ret = ath_rxbuf_init(sc, 120667aaf739SAdrian Chadd sc->sc_rxedma[HAL_RX_QUEUE_HP].m_holdbf); 120767aaf739SAdrian Chadd } 120867aaf739SAdrian Chadd /* 120967aaf739SAdrian Chadd * Next, throw our buffer into the holding entry. The hardware 121067aaf739SAdrian Chadd * may use the descriptor to read the link pointer before 121167aaf739SAdrian Chadd * DMAing the next descriptor in to write out a packet. 121267aaf739SAdrian Chadd */ 121367aaf739SAdrian Chadd sc->sc_rxedma[HAL_RX_QUEUE_HP].m_holdbf = bf; 121467aaf739SAdrian Chadd } while (ret == 0); 1215e60c4fc2SAdrian Chadd 1216e60c4fc2SAdrian Chadd /* rx signal state monitoring */ 1217e60c4fc2SAdrian Chadd ath_hal_rxmonitor(ah, &sc->sc_halstats, sc->sc_curchan); 1218e60c4fc2SAdrian Chadd if (ngood) 1219e60c4fc2SAdrian Chadd sc->sc_lastrx = tsf; 1220e60c4fc2SAdrian Chadd 122103682514SAdrian Chadd ATH_KTR(sc, ATH_KTR_RXPROC, 2, "ath_rx_proc: npkts=%d, ngood=%d", npkts, ngood); 1222e60c4fc2SAdrian Chadd /* Queue DFS tasklet if needed */ 1223e60c4fc2SAdrian Chadd if (resched && ath_dfs_tasklet_needed(sc, sc->sc_curchan)) 1224e60c4fc2SAdrian Chadd taskqueue_enqueue(sc->sc_tq, &sc->sc_dfstask); 1225e60c4fc2SAdrian Chadd 1226e60c4fc2SAdrian Chadd /* 1227e60c4fc2SAdrian Chadd * Now that all the RX frames were handled that 1228e60c4fc2SAdrian Chadd * need to be handled, kick the PCU if there's 1229e60c4fc2SAdrian Chadd * been an RXEOL condition. 1230e60c4fc2SAdrian Chadd */ 12311844ff16SAdrian Chadd if (resched && kickpcu) { 1232e60c4fc2SAdrian Chadd ATH_PCU_LOCK(sc); 123303682514SAdrian Chadd ATH_KTR(sc, ATH_KTR_ERROR, 0, "ath_rx_proc: kickpcu"); 1234e60c4fc2SAdrian Chadd device_printf(sc->sc_dev, "%s: kickpcu; handled %d packets\n", 1235e60c4fc2SAdrian Chadd __func__, npkts); 1236e60c4fc2SAdrian Chadd 12371844ff16SAdrian Chadd /* 12381844ff16SAdrian Chadd * Go through the process of fully tearing down 12391844ff16SAdrian Chadd * the RX buffers and reinitialising them. 12401844ff16SAdrian Chadd * 12411844ff16SAdrian Chadd * There's a hardware bug that causes the RX FIFO 12421844ff16SAdrian Chadd * to get confused under certain conditions and 12431844ff16SAdrian Chadd * constantly write over the same frame, leading 12441844ff16SAdrian Chadd * the RX driver code here to get heavily confused. 12451844ff16SAdrian Chadd */ 124667aaf739SAdrian Chadd /* 124767aaf739SAdrian Chadd * XXX Has RX DMA stopped enough here to just call 124867aaf739SAdrian Chadd * ath_startrecv()? 124967aaf739SAdrian Chadd * XXX Do we need to use the holding buffer to restart 125067aaf739SAdrian Chadd * RX DMA by appending entries to the final 125167aaf739SAdrian Chadd * descriptor? Quite likely. 125267aaf739SAdrian Chadd */ 12531844ff16SAdrian Chadd #if 1 1254233af52dSAdrian Chadd ath_startrecv(sc); 1255233af52dSAdrian Chadd #else 1256e60c4fc2SAdrian Chadd /* 12571844ff16SAdrian Chadd * Disabled for now - it'd be nice to be able to do 12581844ff16SAdrian Chadd * this in order to limit the amount of CPU time spent 12591844ff16SAdrian Chadd * reinitialising the RX side (and thus minimise RX 12601844ff16SAdrian Chadd * drops) however there's a hardware issue that 12611844ff16SAdrian Chadd * causes things to get too far out of whack. 12621844ff16SAdrian Chadd */ 12631844ff16SAdrian Chadd /* 1264e60c4fc2SAdrian Chadd * XXX can we hold the PCU lock here? 1265e60c4fc2SAdrian Chadd * Are there any net80211 buffer calls involved? 1266e60c4fc2SAdrian Chadd */ 1267e60c4fc2SAdrian Chadd bf = TAILQ_FIRST(&sc->sc_rxbuf); 1268d60a0680SAdrian Chadd ath_hal_putrxbuf(ah, bf->bf_daddr, HAL_RX_QUEUE_HP); 1269e60c4fc2SAdrian Chadd ath_hal_rxena(ah); /* enable recv descriptors */ 1270e60c4fc2SAdrian Chadd ath_mode_init(sc); /* set filters, etc. */ 1271a8083b9cSAdrian Chadd ath_hal_startpcurecv(ah, (!! sc->sc_scanning)); /* re-enable PCU/DMA engine */ 1272233af52dSAdrian Chadd #endif 1273e60c4fc2SAdrian Chadd 1274e60c4fc2SAdrian Chadd ath_hal_intrset(ah, sc->sc_imask); 1275e60c4fc2SAdrian Chadd sc->sc_kickpcu = 0; 1276e60c4fc2SAdrian Chadd ATH_PCU_UNLOCK(sc); 12771844ff16SAdrian Chadd } 1278e60c4fc2SAdrian Chadd 1279e60c4fc2SAdrian Chadd #ifdef IEEE80211_SUPPORT_SUPERG 12807a79cebfSGleb Smirnoff if (resched) 1281e60c4fc2SAdrian Chadd ieee80211_ff_age_all(ic, 100); 1282e60c4fc2SAdrian Chadd #endif 1283e60c4fc2SAdrian Chadd 1284516f6796SAdrian Chadd /* 1285f5c30c4eSAdrian Chadd * Put the hardware to sleep again if we're done with it. 1286f5c30c4eSAdrian Chadd */ 1287f5c30c4eSAdrian Chadd ATH_LOCK(sc); 1288f5c30c4eSAdrian Chadd ath_power_restore_power_state(sc); 1289f5c30c4eSAdrian Chadd ATH_UNLOCK(sc); 1290f5c30c4eSAdrian Chadd 1291f5c30c4eSAdrian Chadd /* 1292516f6796SAdrian Chadd * If we hit the maximum number of frames in this round, 1293516f6796SAdrian Chadd * reschedule for another immediate pass. This gives 1294516f6796SAdrian Chadd * the TX and TX completion routines time to run, which 1295516f6796SAdrian Chadd * will reduce latency. 1296516f6796SAdrian Chadd */ 1297516f6796SAdrian Chadd if (npkts >= ATH_RX_MAX) 1298f0db652cSAdrian Chadd sc->sc_rx.recv_sched(sc, resched); 1299516f6796SAdrian Chadd 1300e60c4fc2SAdrian Chadd ATH_PCU_LOCK(sc); 1301e60c4fc2SAdrian Chadd sc->sc_rxproc_cnt--; 1302e60c4fc2SAdrian Chadd ATH_PCU_UNLOCK(sc); 1303e60c4fc2SAdrian Chadd } 13047a79cebfSGleb Smirnoff #undef PA2DESC 1305516f6796SAdrian Chadd #undef ATH_RX_MAX 1306516f6796SAdrian Chadd 1307e60c4fc2SAdrian Chadd /* 1308f8cc9b09SAdrian Chadd * Only run the RX proc if it's not already running. 1309f8cc9b09SAdrian Chadd * Since this may get run as part of the reset/flush path, 1310f8cc9b09SAdrian Chadd * the task can't clash with an existing, running tasklet. 1311f8cc9b09SAdrian Chadd */ 1312f8cc9b09SAdrian Chadd static void 1313f8cc9b09SAdrian Chadd ath_legacy_rx_tasklet(void *arg, int npending) 1314f8cc9b09SAdrian Chadd { 1315f8cc9b09SAdrian Chadd struct ath_softc *sc = arg; 1316af2441fbSAdrian Chadd struct epoch_tracker et; 1317f8cc9b09SAdrian Chadd 131803682514SAdrian Chadd ATH_KTR(sc, ATH_KTR_RXPROC, 1, "ath_rx_proc: pending=%d", npending); 1319f8cc9b09SAdrian Chadd DPRINTF(sc, ATH_DEBUG_RX_PROC, "%s: pending %u\n", __func__, npending); 1320f8cc9b09SAdrian Chadd ATH_PCU_LOCK(sc); 1321f8cc9b09SAdrian Chadd if (sc->sc_inreset_cnt > 0) { 1322f8cc9b09SAdrian Chadd device_printf(sc->sc_dev, 1323f8cc9b09SAdrian Chadd "%s: sc_inreset_cnt > 0; skipping\n", __func__); 1324f8cc9b09SAdrian Chadd ATH_PCU_UNLOCK(sc); 1325f8cc9b09SAdrian Chadd return; 1326f8cc9b09SAdrian Chadd } 1327f8cc9b09SAdrian Chadd ATH_PCU_UNLOCK(sc); 1328f8cc9b09SAdrian Chadd 1329af2441fbSAdrian Chadd NET_EPOCH_ENTER(et); 1330f8cc9b09SAdrian Chadd ath_rx_proc(sc, 1); 1331af2441fbSAdrian Chadd NET_EPOCH_EXIT(et); 1332f8cc9b09SAdrian Chadd } 1333f8cc9b09SAdrian Chadd 1334f8cc9b09SAdrian Chadd static void 1335f8cc9b09SAdrian Chadd ath_legacy_flushrecv(struct ath_softc *sc) 1336f8cc9b09SAdrian Chadd { 1337af2441fbSAdrian Chadd struct epoch_tracker et; 1338af2441fbSAdrian Chadd NET_EPOCH_ENTER(et); 1339f8cc9b09SAdrian Chadd ath_rx_proc(sc, 0); 1340af2441fbSAdrian Chadd NET_EPOCH_EXIT(et); 1341f8cc9b09SAdrian Chadd } 1342f8cc9b09SAdrian Chadd 134367aaf739SAdrian Chadd static void 134467aaf739SAdrian Chadd ath_legacy_flush_rxpending(struct ath_softc *sc) 134567aaf739SAdrian Chadd { 134667aaf739SAdrian Chadd 134767aaf739SAdrian Chadd /* XXX ATH_RX_LOCK_ASSERT(sc); */ 134867aaf739SAdrian Chadd 134967aaf739SAdrian Chadd if (sc->sc_rxedma[HAL_RX_QUEUE_LP].m_rxpending != NULL) { 135067aaf739SAdrian Chadd m_freem(sc->sc_rxedma[HAL_RX_QUEUE_LP].m_rxpending); 135167aaf739SAdrian Chadd sc->sc_rxedma[HAL_RX_QUEUE_LP].m_rxpending = NULL; 135267aaf739SAdrian Chadd } 135367aaf739SAdrian Chadd if (sc->sc_rxedma[HAL_RX_QUEUE_HP].m_rxpending != NULL) { 135467aaf739SAdrian Chadd m_freem(sc->sc_rxedma[HAL_RX_QUEUE_HP].m_rxpending); 135567aaf739SAdrian Chadd sc->sc_rxedma[HAL_RX_QUEUE_HP].m_rxpending = NULL; 135667aaf739SAdrian Chadd } 135767aaf739SAdrian Chadd } 135867aaf739SAdrian Chadd 135967aaf739SAdrian Chadd static int 136067aaf739SAdrian Chadd ath_legacy_flush_rxholdbf(struct ath_softc *sc) 136167aaf739SAdrian Chadd { 136267aaf739SAdrian Chadd struct ath_buf *bf; 136367aaf739SAdrian Chadd 136467aaf739SAdrian Chadd /* XXX ATH_RX_LOCK_ASSERT(sc); */ 136567aaf739SAdrian Chadd /* 136667aaf739SAdrian Chadd * If there are RX holding buffers, free them here and return 136767aaf739SAdrian Chadd * them to the list. 136867aaf739SAdrian Chadd * 136967aaf739SAdrian Chadd * XXX should just verify that bf->bf_m is NULL, as it must 137067aaf739SAdrian Chadd * be at this point! 137167aaf739SAdrian Chadd */ 137267aaf739SAdrian Chadd bf = sc->sc_rxedma[HAL_RX_QUEUE_HP].m_holdbf; 137367aaf739SAdrian Chadd if (bf != NULL) { 137467aaf739SAdrian Chadd if (bf->bf_m != NULL) 137567aaf739SAdrian Chadd m_freem(bf->bf_m); 137667aaf739SAdrian Chadd bf->bf_m = NULL; 137767aaf739SAdrian Chadd TAILQ_INSERT_TAIL(&sc->sc_rxbuf, bf, bf_list); 137867aaf739SAdrian Chadd (void) ath_rxbuf_init(sc, bf); 137967aaf739SAdrian Chadd } 138067aaf739SAdrian Chadd sc->sc_rxedma[HAL_RX_QUEUE_HP].m_holdbf = NULL; 138167aaf739SAdrian Chadd 138267aaf739SAdrian Chadd bf = sc->sc_rxedma[HAL_RX_QUEUE_LP].m_holdbf; 138367aaf739SAdrian Chadd if (bf != NULL) { 138467aaf739SAdrian Chadd if (bf->bf_m != NULL) 138567aaf739SAdrian Chadd m_freem(bf->bf_m); 138667aaf739SAdrian Chadd bf->bf_m = NULL; 138767aaf739SAdrian Chadd TAILQ_INSERT_TAIL(&sc->sc_rxbuf, bf, bf_list); 138867aaf739SAdrian Chadd (void) ath_rxbuf_init(sc, bf); 138967aaf739SAdrian Chadd } 139067aaf739SAdrian Chadd sc->sc_rxedma[HAL_RX_QUEUE_LP].m_holdbf = NULL; 139167aaf739SAdrian Chadd 139267aaf739SAdrian Chadd return (0); 139367aaf739SAdrian Chadd } 139467aaf739SAdrian Chadd 1395f8cc9b09SAdrian Chadd /* 1396e60c4fc2SAdrian Chadd * Disable the receive h/w in preparation for a reset. 1397e60c4fc2SAdrian Chadd */ 1398f8cc9b09SAdrian Chadd static void 1399f8cc9b09SAdrian Chadd ath_legacy_stoprecv(struct ath_softc *sc, int dodelay) 1400e60c4fc2SAdrian Chadd { 1401e60c4fc2SAdrian Chadd #define PA2DESC(_sc, _pa) \ 1402e60c4fc2SAdrian Chadd ((struct ath_desc *)((caddr_t)(_sc)->sc_rxdma.dd_desc + \ 1403e60c4fc2SAdrian Chadd ((_pa) - (_sc)->sc_rxdma.dd_desc_paddr))) 1404e60c4fc2SAdrian Chadd struct ath_hal *ah = sc->sc_ah; 1405e60c4fc2SAdrian Chadd 140667aaf739SAdrian Chadd ATH_RX_LOCK(sc); 140767aaf739SAdrian Chadd 1408e60c4fc2SAdrian Chadd ath_hal_stoppcurecv(ah); /* disable PCU */ 1409e60c4fc2SAdrian Chadd ath_hal_setrxfilter(ah, 0); /* clear recv filter */ 1410e60c4fc2SAdrian Chadd ath_hal_stopdmarecv(ah); /* disable DMA engine */ 1411e60c4fc2SAdrian Chadd /* 1412e60c4fc2SAdrian Chadd * TODO: see if this particular DELAY() is required; it may be 1413e60c4fc2SAdrian Chadd * masking some missing FIFO flush or DMA sync. 1414e60c4fc2SAdrian Chadd */ 1415e60c4fc2SAdrian Chadd #if 0 1416e60c4fc2SAdrian Chadd if (dodelay) 1417e60c4fc2SAdrian Chadd #endif 1418e60c4fc2SAdrian Chadd DELAY(3000); /* 3ms is long enough for 1 frame */ 1419e60c4fc2SAdrian Chadd #ifdef ATH_DEBUG 1420e60c4fc2SAdrian Chadd if (sc->sc_debug & (ATH_DEBUG_RESET | ATH_DEBUG_FATAL)) { 1421e60c4fc2SAdrian Chadd struct ath_buf *bf; 1422e60c4fc2SAdrian Chadd u_int ix; 1423e60c4fc2SAdrian Chadd 1424e60c4fc2SAdrian Chadd device_printf(sc->sc_dev, 1425e60c4fc2SAdrian Chadd "%s: rx queue %p, link %p\n", 1426e60c4fc2SAdrian Chadd __func__, 1427d60a0680SAdrian Chadd (caddr_t)(uintptr_t) ath_hal_getrxbuf(ah, HAL_RX_QUEUE_HP), 1428e60c4fc2SAdrian Chadd sc->sc_rxlink); 1429e60c4fc2SAdrian Chadd ix = 0; 1430e60c4fc2SAdrian Chadd TAILQ_FOREACH(bf, &sc->sc_rxbuf, bf_list) { 1431e60c4fc2SAdrian Chadd struct ath_desc *ds = bf->bf_desc; 1432e60c4fc2SAdrian Chadd struct ath_rx_status *rs = &bf->bf_status.ds_rxstat; 1433e60c4fc2SAdrian Chadd HAL_STATUS status = ath_hal_rxprocdesc(ah, ds, 1434e60c4fc2SAdrian Chadd bf->bf_daddr, PA2DESC(sc, ds->ds_link), rs); 1435e60c4fc2SAdrian Chadd if (status == HAL_OK || (sc->sc_debug & ATH_DEBUG_FATAL)) 1436e60c4fc2SAdrian Chadd ath_printrxbuf(sc, bf, ix, status == HAL_OK); 1437e60c4fc2SAdrian Chadd ix++; 1438e60c4fc2SAdrian Chadd } 1439e60c4fc2SAdrian Chadd } 1440e60c4fc2SAdrian Chadd #endif 144167aaf739SAdrian Chadd 144267aaf739SAdrian Chadd (void) ath_legacy_flush_rxpending(sc); 144367aaf739SAdrian Chadd (void) ath_legacy_flush_rxholdbf(sc); 144467aaf739SAdrian Chadd 1445e60c4fc2SAdrian Chadd sc->sc_rxlink = NULL; /* just in case */ 144667aaf739SAdrian Chadd 144767aaf739SAdrian Chadd ATH_RX_UNLOCK(sc); 1448e60c4fc2SAdrian Chadd #undef PA2DESC 1449e60c4fc2SAdrian Chadd } 1450e60c4fc2SAdrian Chadd 1451e60c4fc2SAdrian Chadd /* 145267aaf739SAdrian Chadd * XXX TODO: something was calling startrecv without calling 145367aaf739SAdrian Chadd * stoprecv. Let's figure out what/why. It was showing up 145467aaf739SAdrian Chadd * as a mbuf leak (rxpending) and ath_buf leak (holdbf.) 145567aaf739SAdrian Chadd */ 145667aaf739SAdrian Chadd 145767aaf739SAdrian Chadd /* 1458e60c4fc2SAdrian Chadd * Enable the receive h/w following a reset. 1459e60c4fc2SAdrian Chadd */ 1460f8cc9b09SAdrian Chadd static int 1461f8cc9b09SAdrian Chadd ath_legacy_startrecv(struct ath_softc *sc) 1462e60c4fc2SAdrian Chadd { 1463e60c4fc2SAdrian Chadd struct ath_hal *ah = sc->sc_ah; 1464e60c4fc2SAdrian Chadd struct ath_buf *bf; 1465e60c4fc2SAdrian Chadd 146667aaf739SAdrian Chadd ATH_RX_LOCK(sc); 146767aaf739SAdrian Chadd 146867aaf739SAdrian Chadd /* 146967aaf739SAdrian Chadd * XXX should verify these are already all NULL! 147067aaf739SAdrian Chadd */ 1471e60c4fc2SAdrian Chadd sc->sc_rxlink = NULL; 147267aaf739SAdrian Chadd (void) ath_legacy_flush_rxpending(sc); 147367aaf739SAdrian Chadd (void) ath_legacy_flush_rxholdbf(sc); 147467aaf739SAdrian Chadd 147567aaf739SAdrian Chadd /* 147667aaf739SAdrian Chadd * Re-chain all of the buffers in the RX buffer list. 147767aaf739SAdrian Chadd */ 1478e60c4fc2SAdrian Chadd TAILQ_FOREACH(bf, &sc->sc_rxbuf, bf_list) { 1479e60c4fc2SAdrian Chadd int error = ath_rxbuf_init(sc, bf); 1480e60c4fc2SAdrian Chadd if (error != 0) { 1481e60c4fc2SAdrian Chadd DPRINTF(sc, ATH_DEBUG_RECV, 1482e60c4fc2SAdrian Chadd "%s: ath_rxbuf_init failed %d\n", 1483e60c4fc2SAdrian Chadd __func__, error); 1484e60c4fc2SAdrian Chadd return error; 1485e60c4fc2SAdrian Chadd } 1486e60c4fc2SAdrian Chadd } 1487e60c4fc2SAdrian Chadd 1488e60c4fc2SAdrian Chadd bf = TAILQ_FIRST(&sc->sc_rxbuf); 1489d60a0680SAdrian Chadd ath_hal_putrxbuf(ah, bf->bf_daddr, HAL_RX_QUEUE_HP); 1490e60c4fc2SAdrian Chadd ath_hal_rxena(ah); /* enable recv descriptors */ 1491e60c4fc2SAdrian Chadd ath_mode_init(sc); /* set filters, etc. */ 1492a8083b9cSAdrian Chadd ath_hal_startpcurecv(ah, (!! sc->sc_scanning)); /* re-enable PCU/DMA engine */ 149367aaf739SAdrian Chadd 149467aaf739SAdrian Chadd ATH_RX_UNLOCK(sc); 1495e60c4fc2SAdrian Chadd return 0; 1496e60c4fc2SAdrian Chadd } 1497f8cc9b09SAdrian Chadd 14983d184db2SAdrian Chadd static int 14993d184db2SAdrian Chadd ath_legacy_dma_rxsetup(struct ath_softc *sc) 15003d184db2SAdrian Chadd { 15013d184db2SAdrian Chadd int error; 15023d184db2SAdrian Chadd 15033d184db2SAdrian Chadd error = ath_descdma_setup(sc, &sc->sc_rxdma, &sc->sc_rxbuf, 15041006fc0cSAdrian Chadd "rx", sizeof(struct ath_desc), ath_rxbuf, 1); 15053d184db2SAdrian Chadd if (error != 0) 15063d184db2SAdrian Chadd return (error); 15073d184db2SAdrian Chadd 15083d184db2SAdrian Chadd return (0); 15093d184db2SAdrian Chadd } 15103d184db2SAdrian Chadd 15113d184db2SAdrian Chadd static int 15123d184db2SAdrian Chadd ath_legacy_dma_rxteardown(struct ath_softc *sc) 15133d184db2SAdrian Chadd { 15143d184db2SAdrian Chadd 15153d184db2SAdrian Chadd if (sc->sc_rxdma.dd_desc_len != 0) 15163d184db2SAdrian Chadd ath_descdma_cleanup(sc, &sc->sc_rxdma, &sc->sc_rxbuf); 15173d184db2SAdrian Chadd return (0); 15183d184db2SAdrian Chadd } 1519f8cc9b09SAdrian Chadd 1520f0db652cSAdrian Chadd static void 1521f0db652cSAdrian Chadd ath_legacy_recv_sched(struct ath_softc *sc, int dosched) 1522f0db652cSAdrian Chadd { 1523f0db652cSAdrian Chadd 1524f0db652cSAdrian Chadd taskqueue_enqueue(sc->sc_tq, &sc->sc_rxtask); 1525f0db652cSAdrian Chadd } 1526f0db652cSAdrian Chadd 1527f0db652cSAdrian Chadd static void 1528f0db652cSAdrian Chadd ath_legacy_recv_sched_queue(struct ath_softc *sc, HAL_RX_QUEUE q, 1529f0db652cSAdrian Chadd int dosched) 1530f0db652cSAdrian Chadd { 1531f0db652cSAdrian Chadd 1532f0db652cSAdrian Chadd taskqueue_enqueue(sc->sc_tq, &sc->sc_rxtask); 1533f0db652cSAdrian Chadd } 1534f0db652cSAdrian Chadd 1535f8cc9b09SAdrian Chadd void 1536f8cc9b09SAdrian Chadd ath_recv_setup_legacy(struct ath_softc *sc) 1537f8cc9b09SAdrian Chadd { 1538f8cc9b09SAdrian Chadd 15391006fc0cSAdrian Chadd /* Sensible legacy defaults */ 1540bb327d28SAdrian Chadd /* 1541bb327d28SAdrian Chadd * XXX this should be changed to properly support the 1542bb327d28SAdrian Chadd * exact RX descriptor size for each HAL. 1543bb327d28SAdrian Chadd */ 1544bb327d28SAdrian Chadd sc->sc_rx_statuslen = sizeof(struct ath_desc); 15451006fc0cSAdrian Chadd 1546f8cc9b09SAdrian Chadd sc->sc_rx.recv_start = ath_legacy_startrecv; 1547f8cc9b09SAdrian Chadd sc->sc_rx.recv_stop = ath_legacy_stoprecv; 1548f8cc9b09SAdrian Chadd sc->sc_rx.recv_flush = ath_legacy_flushrecv; 1549f8cc9b09SAdrian Chadd sc->sc_rx.recv_tasklet = ath_legacy_rx_tasklet; 1550f8cc9b09SAdrian Chadd sc->sc_rx.recv_rxbuf_init = ath_legacy_rxbuf_init; 15513d184db2SAdrian Chadd 15523d184db2SAdrian Chadd sc->sc_rx.recv_setup = ath_legacy_dma_rxsetup; 15533d184db2SAdrian Chadd sc->sc_rx.recv_teardown = ath_legacy_dma_rxteardown; 1554f0db652cSAdrian Chadd sc->sc_rx.recv_sched = ath_legacy_recv_sched; 1555f0db652cSAdrian Chadd sc->sc_rx.recv_sched_queue = ath_legacy_recv_sched_queue; 1556f8cc9b09SAdrian Chadd } 1557