Home | History | Annotate | Line # | Download | only in ar5211
      1  1.1  alc /*
      2  1.1  alc  * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
      3  1.1  alc  * Copyright (c) 2002-2006 Atheros Communications, Inc.
      4  1.1  alc  *
      5  1.1  alc  * Permission to use, copy, modify, and/or distribute this software for any
      6  1.1  alc  * purpose with or without fee is hereby granted, provided that the above
      7  1.1  alc  * copyright notice and this permission notice appear in all copies.
      8  1.1  alc  *
      9  1.1  alc  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     10  1.1  alc  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     11  1.1  alc  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     12  1.1  alc  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     13  1.1  alc  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     14  1.1  alc  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     15  1.1  alc  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     16  1.1  alc  *
     17  1.2  mrg  * $Id: ar5211_beacon.c,v 1.2 2009/01/06 06:03:57 mrg Exp $
     18  1.1  alc  */
     19  1.1  alc #include "opt_ah.h"
     20  1.1  alc 
     21  1.1  alc #include "ah.h"
     22  1.1  alc #include "ah_internal.h"
     23  1.1  alc 
     24  1.1  alc #include "ar5211/ar5211.h"
     25  1.1  alc #include "ar5211/ar5211reg.h"
     26  1.1  alc #include "ar5211/ar5211desc.h"
     27  1.1  alc 
     28  1.1  alc /*
     29  1.1  alc  * Routines used to initialize and generated beacons for the AR5211/AR5311.
     30  1.1  alc  */
     31  1.1  alc 
     32  1.1  alc /*
     33  1.1  alc  * Initialize all of the hardware registers used to send beacons.
     34  1.1  alc  */
     35  1.1  alc void
     36  1.1  alc ar5211SetBeaconTimers(struct ath_hal *ah, const HAL_BEACON_TIMERS *bt)
     37  1.1  alc {
     38  1.1  alc 
     39  1.1  alc 	OS_REG_WRITE(ah, AR_TIMER0, bt->bt_nexttbtt);
     40  1.1  alc 	OS_REG_WRITE(ah, AR_TIMER1, bt->bt_nextdba);
     41  1.1  alc 	OS_REG_WRITE(ah, AR_TIMER2, bt->bt_nextswba);
     42  1.1  alc 	OS_REG_WRITE(ah, AR_TIMER3, bt->bt_nextatim);
     43  1.1  alc 	/*
     44  1.1  alc 	 * Set the Beacon register after setting all timers.
     45  1.1  alc 	 */
     46  1.1  alc 	OS_REG_WRITE(ah, AR_BEACON, bt->bt_intval);
     47  1.1  alc }
     48  1.1  alc 
     49  1.1  alc /*
     50  1.1  alc  * Legacy api to initialize all of the beacon registers.
     51  1.1  alc  */
     52  1.1  alc void
     53  1.1  alc ar5211BeaconInit(struct ath_hal *ah,
     54  1.1  alc 	uint32_t next_beacon, uint32_t beacon_period)
     55  1.1  alc {
     56  1.1  alc 	HAL_BEACON_TIMERS bt;
     57  1.1  alc 
     58  1.2  mrg 	bt.bt_nextdba = 0;
     59  1.2  mrg 	bt.bt_nextswba = 0;
     60  1.1  alc 	bt.bt_nexttbtt = next_beacon;
     61  1.1  alc 	/*
     62  1.1  alc 	 * TIMER1: in AP/adhoc mode this controls the DMA beacon
     63  1.1  alc 	 * alert timer; otherwise it controls the next wakeup time.
     64  1.1  alc 	 * TIMER2: in AP mode, it controls the SBA beacon alert
     65  1.1  alc 	 * interrupt; otherwise it sets the start of the next CFP.
     66  1.1  alc 	 */
     67  1.1  alc 	switch (AH_PRIVATE(ah)->ah_opmode) {
     68  1.1  alc 	case HAL_M_STA:
     69  1.1  alc 	case HAL_M_MONITOR:
     70  1.1  alc 		bt.bt_nextdba = 0xffff;
     71  1.1  alc 		bt.bt_nextswba = 0x7ffff;
     72  1.1  alc 		break;
     73  1.1  alc 	case HAL_M_IBSS:
     74  1.1  alc 	case HAL_M_HOSTAP:
     75  1.1  alc 		bt.bt_nextdba = (next_beacon -
     76  1.1  alc 			ath_hal_dma_beacon_response_time) << 3;	/* 1/8 TU */
     77  1.1  alc 		bt.bt_nextswba = (next_beacon -
     78  1.1  alc 			ath_hal_sw_beacon_response_time) << 3;	/* 1/8 TU */
     79  1.1  alc 		break;
     80  1.1  alc 	}
     81  1.1  alc 	/*
     82  1.1  alc 	 * Set the ATIM window
     83  1.1  alc 	 * Our hardware does not support an ATIM window of 0
     84  1.1  alc 	 * (beacons will not work).  If the ATIM windows is 0,
     85  1.1  alc 	 * force it to 1.
     86  1.1  alc 	 */
     87  1.1  alc 	bt.bt_nextatim = next_beacon + 1;
     88  1.1  alc 	bt.bt_intval = beacon_period &
     89  1.1  alc 		(AR_BEACON_PERIOD | AR_BEACON_RESET_TSF | AR_BEACON_EN);
     90  1.1  alc 	ar5211SetBeaconTimers(ah, &bt);
     91  1.1  alc }
     92  1.1  alc 
     93  1.1  alc void
     94  1.1  alc ar5211ResetStaBeaconTimers(struct ath_hal *ah)
     95  1.1  alc {
     96  1.1  alc 	uint32_t val;
     97  1.1  alc 
     98  1.1  alc 	OS_REG_WRITE(ah, AR_TIMER0, 0);		/* no beacons */
     99  1.1  alc 	val = OS_REG_READ(ah, AR_STA_ID1);
    100  1.1  alc 	val |= AR_STA_ID1_PWR_SAV;		/* XXX */
    101  1.1  alc 	/* tell the h/w that the associated AP is not PCF capable */
    102  1.1  alc 	OS_REG_WRITE(ah, AR_STA_ID1,
    103  1.1  alc 		val & ~(AR_STA_ID1_DEFAULT_ANTENNA | AR_STA_ID1_PCF));
    104  1.1  alc 	OS_REG_WRITE(ah, AR_BEACON, AR_BEACON_PERIOD);
    105  1.1  alc }
    106  1.1  alc 
    107  1.1  alc /*
    108  1.1  alc  * Set all the beacon related bits on the h/w for stations
    109  1.1  alc  * i.e. initializes the corresponding h/w timers;
    110  1.1  alc  * also tells the h/w whether to anticipate PCF beacons
    111  1.1  alc  */
    112  1.1  alc void
    113  1.1  alc ar5211SetStaBeaconTimers(struct ath_hal *ah, const HAL_BEACON_STATE *bs)
    114  1.1  alc {
    115  1.1  alc 	struct ath_hal_5211 *ahp = AH5211(ah);
    116  1.1  alc 
    117  1.1  alc 	HALDEBUG(ah, HAL_DEBUG_BEACON, "%s: setting beacon timers\n", __func__);
    118  1.1  alc 
    119  1.1  alc 	HALASSERT(bs->bs_intval != 0);
    120  1.1  alc 	/* if the AP will do PCF */
    121  1.1  alc 	if (bs->bs_cfpmaxduration != 0) {
    122  1.1  alc 		/* tell the h/w that the associated AP is PCF capable */
    123  1.1  alc 		OS_REG_WRITE(ah, AR_STA_ID1,
    124  1.1  alc 			OS_REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PCF);
    125  1.1  alc 
    126  1.1  alc 		/* set CFP_PERIOD(1.024ms) register */
    127  1.1  alc 		OS_REG_WRITE(ah, AR_CFP_PERIOD, bs->bs_cfpperiod);
    128  1.1  alc 
    129  1.1  alc 		/* set CFP_DUR(1.024ms) register to max cfp duration */
    130  1.1  alc 		OS_REG_WRITE(ah, AR_CFP_DUR, bs->bs_cfpmaxduration);
    131  1.1  alc 
    132  1.1  alc 		/* set TIMER2(128us) to anticipated time of next CFP */
    133  1.1  alc 		OS_REG_WRITE(ah, AR_TIMER2, bs->bs_cfpnext << 3);
    134  1.1  alc 	} else {
    135  1.1  alc 		/* tell the h/w that the associated AP is not PCF capable */
    136  1.1  alc 		OS_REG_WRITE(ah, AR_STA_ID1,
    137  1.1  alc 			OS_REG_READ(ah, AR_STA_ID1) &~ AR_STA_ID1_PCF);
    138  1.1  alc 	}
    139  1.1  alc 
    140  1.1  alc 	/*
    141  1.1  alc 	 * Set TIMER0(1.024ms) to the anticipated time of the next beacon.
    142  1.1  alc 	 */
    143  1.1  alc 	OS_REG_WRITE(ah, AR_TIMER0, bs->bs_nexttbtt);
    144  1.1  alc 
    145  1.1  alc 	/*
    146  1.1  alc 	 * Start the beacon timers by setting the BEACON register
    147  1.1  alc 	 * to the beacon interval; also write the tim offset which
    148  1.1  alc 	 * we should know by now.  The code, in ar5211WriteAssocid,
    149  1.1  alc 	 * also sets the tim offset once the AID is known which can
    150  1.1  alc 	 * be left as such for now.
    151  1.1  alc 	 */
    152  1.1  alc 	OS_REG_WRITE(ah, AR_BEACON,
    153  1.1  alc 		(OS_REG_READ(ah, AR_BEACON) &~ (AR_BEACON_PERIOD|AR_BEACON_TIM))
    154  1.1  alc 		| SM(bs->bs_intval, AR_BEACON_PERIOD)
    155  1.1  alc 		| SM(bs->bs_timoffset ? bs->bs_timoffset + 4 : 0, AR_BEACON_TIM)
    156  1.1  alc 	);
    157  1.1  alc 
    158  1.1  alc 	/*
    159  1.1  alc 	 * Configure the BMISS interrupt.  Note that we
    160  1.1  alc 	 * assume the caller blocks interrupts while enabling
    161  1.1  alc 	 * the threshold.
    162  1.1  alc 	 */
    163  1.1  alc 	HALASSERT(bs->bs_bmissthreshold <= MS(0xffffffff, AR_RSSI_THR_BM_THR));
    164  1.1  alc 	ahp->ah_rssiThr = (ahp->ah_rssiThr &~ AR_RSSI_THR_BM_THR)
    165  1.1  alc 			| SM(bs->bs_bmissthreshold, AR_RSSI_THR_BM_THR);
    166  1.1  alc 	OS_REG_WRITE(ah, AR_RSSI_THR, ahp->ah_rssiThr);
    167  1.1  alc 
    168  1.1  alc 	/*
    169  1.1  alc 	 * Set the sleep duration in 1/8 TU's.
    170  1.1  alc 	 */
    171  1.1  alc #define	SLEEP_SLOP	3
    172  1.1  alc 	OS_REG_RMW_FIELD(ah, AR_SCR, AR_SCR_SLDUR,
    173  1.1  alc 		(bs->bs_sleepduration - SLEEP_SLOP) << 3);
    174  1.1  alc #undef SLEEP_SLOP
    175  1.1  alc }
    176