2010-03-17 16:55:25 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2010 Atheros Communications Inc.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "htc.h"
|
|
|
|
|
|
|
|
#define FUDGE 2
|
|
|
|
|
2011-04-13 13:53:26 +08:00
|
|
|
void ath9k_htc_beaconq_config(struct ath9k_htc_priv *priv)
|
|
|
|
{
|
|
|
|
struct ath_hw *ah = priv->ah;
|
|
|
|
struct ath9k_tx_queue_info qi, qi_be;
|
|
|
|
|
|
|
|
memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
|
|
|
|
memset(&qi_be, 0, sizeof(struct ath9k_tx_queue_info));
|
|
|
|
|
|
|
|
ath9k_hw_get_txq_props(ah, priv->beaconq, &qi);
|
|
|
|
|
|
|
|
if (priv->ah->opmode == NL80211_IFTYPE_AP) {
|
|
|
|
qi.tqi_aifs = 1;
|
|
|
|
qi.tqi_cwmin = 0;
|
|
|
|
qi.tqi_cwmax = 0;
|
|
|
|
} else if (priv->ah->opmode == NL80211_IFTYPE_ADHOC) {
|
|
|
|
int qnum = priv->hwq_map[WME_AC_BE];
|
|
|
|
|
|
|
|
ath9k_hw_get_txq_props(ah, qnum, &qi_be);
|
|
|
|
|
|
|
|
qi.tqi_aifs = qi_be.tqi_aifs;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For WIFI Beacon Distribution
|
|
|
|
* Long slot time : 2x cwmin
|
|
|
|
* Short slot time : 4x cwmin
|
|
|
|
*/
|
|
|
|
if (ah->slottime == ATH9K_SLOT_TIME_20)
|
|
|
|
qi.tqi_cwmin = 2*qi_be.tqi_cwmin;
|
|
|
|
else
|
|
|
|
qi.tqi_cwmin = 4*qi_be.tqi_cwmin;
|
|
|
|
|
|
|
|
qi.tqi_cwmax = qi_be.tqi_cwmax;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ath9k_hw_set_txq_props(ah, priv->beaconq, &qi)) {
|
|
|
|
ath_err(ath9k_hw_common(ah),
|
|
|
|
"Unable to update beacon queue %u!\n", priv->beaconq);
|
|
|
|
} else {
|
|
|
|
ath9k_hw_resettxqueue(ah, priv->beaconq);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-17 16:55:25 +08:00
|
|
|
static void ath9k_htc_beacon_config_sta(struct ath9k_htc_priv *priv,
|
2010-04-05 17:18:06 +08:00
|
|
|
struct htc_beacon_config *bss_conf)
|
2010-03-17 16:55:25 +08:00
|
|
|
{
|
|
|
|
struct ath_common *common = ath9k_hw_common(priv->ah);
|
|
|
|
struct ath9k_beacon_state bs;
|
|
|
|
enum ath9k_int imask = 0;
|
|
|
|
int dtimperiod, dtimcount, sleepduration;
|
|
|
|
int cfpperiod, cfpcount, bmiss_timeout;
|
2010-04-16 14:24:03 +08:00
|
|
|
u32 nexttbtt = 0, intval, tsftu;
|
|
|
|
__be32 htc_imask = 0;
|
2010-03-17 16:55:25 +08:00
|
|
|
u64 tsf;
|
|
|
|
int num_beacons, offset, dtim_dec_count, cfp_dec_count;
|
|
|
|
int ret;
|
|
|
|
u8 cmd_rsp;
|
|
|
|
|
|
|
|
memset(&bs, 0, sizeof(bs));
|
|
|
|
|
2010-04-05 17:18:06 +08:00
|
|
|
intval = bss_conf->beacon_interval & ATH9K_BEACON_PERIOD;
|
|
|
|
bmiss_timeout = (ATH_DEFAULT_BMISS_LIMIT * bss_conf->beacon_interval);
|
2010-03-17 16:55:25 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup dtim and cfp parameters according to
|
|
|
|
* last beacon we received (which may be none).
|
|
|
|
*/
|
|
|
|
dtimperiod = bss_conf->dtim_period;
|
|
|
|
if (dtimperiod <= 0) /* NB: 0 if not known */
|
|
|
|
dtimperiod = 1;
|
|
|
|
dtimcount = 1;
|
|
|
|
if (dtimcount >= dtimperiod) /* NB: sanity check */
|
|
|
|
dtimcount = 0;
|
|
|
|
cfpperiod = 1; /* NB: no PCF support yet */
|
|
|
|
cfpcount = 0;
|
|
|
|
|
|
|
|
sleepduration = intval;
|
|
|
|
if (sleepduration <= 0)
|
|
|
|
sleepduration = intval;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pull nexttbtt forward to reflect the current
|
|
|
|
* TSF and calculate dtim+cfp state for the result.
|
|
|
|
*/
|
|
|
|
tsf = ath9k_hw_gettsf64(priv->ah);
|
|
|
|
tsftu = TSF_TO_TU(tsf>>32, tsf) + FUDGE;
|
|
|
|
|
|
|
|
num_beacons = tsftu / intval + 1;
|
|
|
|
offset = tsftu % intval;
|
|
|
|
nexttbtt = tsftu - offset;
|
|
|
|
if (offset)
|
|
|
|
nexttbtt += intval;
|
|
|
|
|
|
|
|
/* DTIM Beacon every dtimperiod Beacon */
|
|
|
|
dtim_dec_count = num_beacons % dtimperiod;
|
|
|
|
/* CFP every cfpperiod DTIM Beacon */
|
|
|
|
cfp_dec_count = (num_beacons / dtimperiod) % cfpperiod;
|
|
|
|
if (dtim_dec_count)
|
|
|
|
cfp_dec_count++;
|
|
|
|
|
|
|
|
dtimcount -= dtim_dec_count;
|
|
|
|
if (dtimcount < 0)
|
|
|
|
dtimcount += dtimperiod;
|
|
|
|
|
|
|
|
cfpcount -= cfp_dec_count;
|
|
|
|
if (cfpcount < 0)
|
|
|
|
cfpcount += cfpperiod;
|
|
|
|
|
|
|
|
bs.bs_intval = intval;
|
|
|
|
bs.bs_nexttbtt = nexttbtt;
|
|
|
|
bs.bs_dtimperiod = dtimperiod*intval;
|
|
|
|
bs.bs_nextdtim = bs.bs_nexttbtt + dtimcount*intval;
|
|
|
|
bs.bs_cfpperiod = cfpperiod*bs.bs_dtimperiod;
|
|
|
|
bs.bs_cfpnext = bs.bs_nextdtim + cfpcount*bs.bs_dtimperiod;
|
|
|
|
bs.bs_cfpmaxduration = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate the number of consecutive beacons to miss* before taking
|
|
|
|
* a BMISS interrupt. The configuration is specified in TU so we only
|
|
|
|
* need calculate based on the beacon interval. Note that we clamp the
|
|
|
|
* result to at most 15 beacons.
|
|
|
|
*/
|
|
|
|
if (sleepduration > intval) {
|
|
|
|
bs.bs_bmissthreshold = ATH_DEFAULT_BMISS_LIMIT / 2;
|
|
|
|
} else {
|
|
|
|
bs.bs_bmissthreshold = DIV_ROUND_UP(bmiss_timeout, intval);
|
|
|
|
if (bs.bs_bmissthreshold > 15)
|
|
|
|
bs.bs_bmissthreshold = 15;
|
|
|
|
else if (bs.bs_bmissthreshold <= 0)
|
|
|
|
bs.bs_bmissthreshold = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate sleep duration. The configuration is given in ms.
|
|
|
|
* We ensure a multiple of the beacon period is used. Also, if the sleep
|
|
|
|
* duration is greater than the DTIM period then it makes senses
|
|
|
|
* to make it a multiple of that.
|
|
|
|
*
|
|
|
|
* XXX fixed at 100ms
|
|
|
|
*/
|
|
|
|
|
|
|
|
bs.bs_sleepduration = roundup(IEEE80211_MS_TO_TU(100), sleepduration);
|
|
|
|
if (bs.bs_sleepduration > bs.bs_dtimperiod)
|
|
|
|
bs.bs_sleepduration = bs.bs_dtimperiod;
|
|
|
|
|
|
|
|
/* TSF out of range threshold fixed at 1 second */
|
|
|
|
bs.bs_tsfoor_threshold = ATH9K_TSFOOR_THRESHOLD;
|
|
|
|
|
2011-02-27 11:50:40 +08:00
|
|
|
ath_dbg(common, ATH_DBG_CONFIG, "intval: %u tsf: %llu tsftu: %u\n",
|
|
|
|
intval, tsf, tsftu);
|
|
|
|
ath_dbg(common, ATH_DBG_CONFIG,
|
2010-12-03 11:12:37 +08:00
|
|
|
"bmiss: %u sleep: %u cfp-period: %u maxdur: %u next: %u\n",
|
|
|
|
bs.bs_bmissthreshold, bs.bs_sleepduration,
|
|
|
|
bs.bs_cfpperiod, bs.bs_cfpmaxduration, bs.bs_cfpnext);
|
2010-03-17 16:55:25 +08:00
|
|
|
|
|
|
|
/* Set the computed STA beacon timers */
|
|
|
|
|
|
|
|
WMI_CMD(WMI_DISABLE_INTR_CMDID);
|
|
|
|
ath9k_hw_set_sta_beacon_timers(priv->ah, &bs);
|
|
|
|
imask |= ATH9K_INT_BMISS;
|
|
|
|
htc_imask = cpu_to_be32(imask);
|
|
|
|
WMI_CMD_BUF(WMI_ENABLE_INTR_CMDID, &htc_imask);
|
|
|
|
}
|
|
|
|
|
2011-02-21 10:19:53 +08:00
|
|
|
static void ath9k_htc_beacon_config_ap(struct ath9k_htc_priv *priv,
|
|
|
|
struct htc_beacon_config *bss_conf)
|
|
|
|
{
|
|
|
|
struct ath_common *common = ath9k_hw_common(priv->ah);
|
|
|
|
enum ath9k_int imask = 0;
|
|
|
|
u32 nexttbtt, intval, tsftu;
|
|
|
|
__be32 htc_imask = 0;
|
|
|
|
int ret;
|
|
|
|
u8 cmd_rsp;
|
|
|
|
u64 tsf;
|
|
|
|
|
|
|
|
intval = bss_conf->beacon_interval & ATH9K_BEACON_PERIOD;
|
|
|
|
intval /= ATH9K_HTC_MAX_BCN_VIF;
|
|
|
|
nexttbtt = intval;
|
|
|
|
|
|
|
|
if (priv->op_flags & OP_TSF_RESET) {
|
2011-03-23 04:54:17 +08:00
|
|
|
ath9k_hw_reset_tsf(priv->ah);
|
2011-02-21 10:19:53 +08:00
|
|
|
priv->op_flags &= ~OP_TSF_RESET;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Pull nexttbtt forward to reflect the current TSF.
|
|
|
|
*/
|
|
|
|
tsf = ath9k_hw_gettsf64(priv->ah);
|
|
|
|
tsftu = TSF_TO_TU(tsf >> 32, tsf) + FUDGE;
|
|
|
|
do {
|
|
|
|
nexttbtt += intval;
|
|
|
|
} while (nexttbtt < tsftu);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->op_flags & OP_ENABLE_BEACON)
|
|
|
|
imask |= ATH9K_INT_SWBA;
|
|
|
|
|
|
|
|
ath_dbg(common, ATH_DBG_CONFIG,
|
2011-04-13 13:53:08 +08:00
|
|
|
"AP Beacon config, intval: %d, nexttbtt: %u "
|
|
|
|
"imask: 0x%x\n",
|
2011-02-21 10:19:53 +08:00
|
|
|
bss_conf->beacon_interval, nexttbtt, imask);
|
|
|
|
|
2011-04-13 13:53:26 +08:00
|
|
|
ath9k_htc_beaconq_config(priv);
|
|
|
|
|
2011-02-21 10:19:53 +08:00
|
|
|
WMI_CMD(WMI_DISABLE_INTR_CMDID);
|
2011-03-23 04:54:17 +08:00
|
|
|
ath9k_hw_beaconinit(priv->ah, TU_TO_USEC(nexttbtt), TU_TO_USEC(intval));
|
2011-04-13 13:53:08 +08:00
|
|
|
priv->cur_beacon_conf.bmiss_cnt = 0;
|
2011-02-21 10:19:53 +08:00
|
|
|
htc_imask = cpu_to_be32(imask);
|
|
|
|
WMI_CMD_BUF(WMI_ENABLE_INTR_CMDID, &htc_imask);
|
|
|
|
}
|
|
|
|
|
2010-03-17 16:55:25 +08:00
|
|
|
static void ath9k_htc_beacon_config_adhoc(struct ath9k_htc_priv *priv,
|
2010-04-05 17:18:06 +08:00
|
|
|
struct htc_beacon_config *bss_conf)
|
2010-03-17 16:55:25 +08:00
|
|
|
{
|
|
|
|
struct ath_common *common = ath9k_hw_common(priv->ah);
|
|
|
|
enum ath9k_int imask = 0;
|
2011-02-21 10:20:01 +08:00
|
|
|
u32 nexttbtt, intval, tsftu;
|
2010-04-16 14:24:03 +08:00
|
|
|
__be32 htc_imask = 0;
|
2010-03-17 16:55:25 +08:00
|
|
|
int ret;
|
|
|
|
u8 cmd_rsp;
|
2011-02-21 10:20:01 +08:00
|
|
|
u64 tsf;
|
2010-03-17 16:55:25 +08:00
|
|
|
|
2010-04-05 17:18:06 +08:00
|
|
|
intval = bss_conf->beacon_interval & ATH9K_BEACON_PERIOD;
|
2010-03-17 16:55:25 +08:00
|
|
|
nexttbtt = intval;
|
2011-02-21 10:20:01 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Pull nexttbtt forward to reflect the current TSF.
|
|
|
|
*/
|
|
|
|
tsf = ath9k_hw_gettsf64(priv->ah);
|
|
|
|
tsftu = TSF_TO_TU(tsf >> 32, tsf) + FUDGE;
|
|
|
|
do {
|
|
|
|
nexttbtt += intval;
|
|
|
|
} while (nexttbtt < tsftu);
|
|
|
|
|
2010-03-17 16:55:25 +08:00
|
|
|
if (priv->op_flags & OP_ENABLE_BEACON)
|
|
|
|
imask |= ATH9K_INT_SWBA;
|
|
|
|
|
2011-02-21 10:20:01 +08:00
|
|
|
ath_dbg(common, ATH_DBG_CONFIG,
|
|
|
|
"IBSS Beacon config, intval: %d, nexttbtt: %u, imask: 0x%x\n",
|
|
|
|
bss_conf->beacon_interval, nexttbtt, imask);
|
2010-03-17 16:55:25 +08:00
|
|
|
|
|
|
|
WMI_CMD(WMI_DISABLE_INTR_CMDID);
|
2011-03-23 04:54:17 +08:00
|
|
|
ath9k_hw_beaconinit(priv->ah, TU_TO_USEC(nexttbtt), TU_TO_USEC(intval));
|
2011-04-13 13:53:08 +08:00
|
|
|
priv->cur_beacon_conf.bmiss_cnt = 0;
|
2010-03-17 16:55:25 +08:00
|
|
|
htc_imask = cpu_to_be32(imask);
|
|
|
|
WMI_CMD_BUF(WMI_ENABLE_INTR_CMDID, &htc_imask);
|
|
|
|
}
|
|
|
|
|
2010-05-06 17:15:47 +08:00
|
|
|
void ath9k_htc_beaconep(void *drv_priv, struct sk_buff *skb,
|
|
|
|
enum htc_endpoint_id ep_id, bool txok)
|
2010-03-17 16:55:25 +08:00
|
|
|
{
|
2010-05-06 17:15:47 +08:00
|
|
|
dev_kfree_skb_any(skb);
|
2010-03-17 16:55:25 +08:00
|
|
|
}
|
|
|
|
|
2011-04-13 13:53:34 +08:00
|
|
|
static void ath9k_htc_send_buffered(struct ath9k_htc_priv *priv,
|
|
|
|
int slot)
|
|
|
|
{
|
|
|
|
struct ath_common *common = ath9k_hw_common(priv->ah);
|
|
|
|
struct ieee80211_vif *vif;
|
|
|
|
struct sk_buff *skb;
|
|
|
|
struct ieee80211_hdr *hdr;
|
|
|
|
int padpos, padsize, ret;
|
|
|
|
|
|
|
|
spin_lock_bh(&priv->beacon_lock);
|
|
|
|
|
|
|
|
vif = priv->cur_beacon_conf.bslot[slot];
|
|
|
|
|
|
|
|
skb = ieee80211_get_buffered_bc(priv->hw, vif);
|
|
|
|
|
|
|
|
while(skb) {
|
|
|
|
hdr = (struct ieee80211_hdr *) skb->data;
|
|
|
|
|
|
|
|
padpos = ath9k_cmn_padpos(hdr->frame_control);
|
|
|
|
padsize = padpos & 3;
|
|
|
|
if (padsize && skb->len > padpos) {
|
|
|
|
if (skb_headroom(skb) < padsize) {
|
|
|
|
dev_kfree_skb_any(skb);
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
skb_push(skb, padsize);
|
|
|
|
memmove(skb->data, skb->data + padsize, padpos);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = ath9k_htc_tx_start(priv, skb, true);
|
|
|
|
if (ret != 0) {
|
|
|
|
ath_dbg(common, ATH_DBG_FATAL,
|
|
|
|
"Failed to send CAB frame\n");
|
|
|
|
dev_kfree_skb_any(skb);
|
|
|
|
}
|
|
|
|
next:
|
|
|
|
skb = ieee80211_get_buffered_bc(priv->hw, vif);
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_bh(&priv->beacon_lock);
|
|
|
|
}
|
|
|
|
|
2011-04-13 13:53:08 +08:00
|
|
|
static void ath9k_htc_send_beacon(struct ath9k_htc_priv *priv,
|
|
|
|
int slot)
|
2010-03-17 16:55:25 +08:00
|
|
|
{
|
2011-04-13 13:53:08 +08:00
|
|
|
struct ieee80211_vif *vif;
|
|
|
|
struct ath9k_htc_vif *avp;
|
2010-03-17 16:55:25 +08:00
|
|
|
struct tx_beacon_header beacon_hdr;
|
|
|
|
struct ath9k_htc_tx_ctl tx_ctl;
|
|
|
|
struct ieee80211_tx_info *info;
|
2011-04-13 13:53:17 +08:00
|
|
|
struct ieee80211_mgmt *mgmt;
|
2010-05-06 17:15:47 +08:00
|
|
|
struct sk_buff *beacon;
|
2010-03-17 16:55:25 +08:00
|
|
|
u8 *tx_fhdr;
|
|
|
|
|
|
|
|
memset(&beacon_hdr, 0, sizeof(struct tx_beacon_header));
|
|
|
|
memset(&tx_ctl, 0, sizeof(struct ath9k_htc_tx_ctl));
|
|
|
|
|
|
|
|
spin_lock_bh(&priv->beacon_lock);
|
|
|
|
|
2011-04-13 13:53:08 +08:00
|
|
|
vif = priv->cur_beacon_conf.bslot[slot];
|
|
|
|
avp = (struct ath9k_htc_vif *)vif->drv_priv;
|
|
|
|
|
2010-03-17 16:55:25 +08:00
|
|
|
if (unlikely(priv->op_flags & OP_SCANNING)) {
|
|
|
|
spin_unlock_bh(&priv->beacon_lock);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get a new beacon */
|
2011-04-13 13:53:08 +08:00
|
|
|
beacon = ieee80211_beacon_get(priv->hw, vif);
|
2010-05-06 17:15:47 +08:00
|
|
|
if (!beacon) {
|
2010-03-17 16:55:25 +08:00
|
|
|
spin_unlock_bh(&priv->beacon_lock);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-13 13:53:17 +08:00
|
|
|
/*
|
|
|
|
* Update the TSF adjust value here, the HW will
|
|
|
|
* add this value for every beacon.
|
|
|
|
*/
|
|
|
|
mgmt = (struct ieee80211_mgmt *)beacon->data;
|
|
|
|
mgmt->u.beacon.timestamp = avp->tsfadjust;
|
|
|
|
|
2010-05-06 17:15:47 +08:00
|
|
|
info = IEEE80211_SKB_CB(beacon);
|
2010-03-17 16:55:25 +08:00
|
|
|
if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
|
|
|
|
struct ieee80211_hdr *hdr =
|
2010-05-06 17:15:47 +08:00
|
|
|
(struct ieee80211_hdr *) beacon->data;
|
2011-02-21 10:18:53 +08:00
|
|
|
avp->seq_no += 0x10;
|
2010-03-17 16:55:25 +08:00
|
|
|
hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
|
2011-02-21 10:18:53 +08:00
|
|
|
hdr->seq_ctrl |= cpu_to_le16(avp->seq_no);
|
2010-03-17 16:55:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
tx_ctl.type = ATH9K_HTC_NORMAL;
|
|
|
|
beacon_hdr.vif_index = avp->index;
|
2010-05-06 17:15:47 +08:00
|
|
|
tx_fhdr = skb_push(beacon, sizeof(beacon_hdr));
|
2010-03-17 16:55:25 +08:00
|
|
|
memcpy(tx_fhdr, (u8 *) &beacon_hdr, sizeof(beacon_hdr));
|
|
|
|
|
2010-05-06 17:15:47 +08:00
|
|
|
htc_send(priv->htc, beacon, priv->beacon_ep, &tx_ctl);
|
2010-03-17 16:55:25 +08:00
|
|
|
|
|
|
|
spin_unlock_bh(&priv->beacon_lock);
|
|
|
|
}
|
|
|
|
|
2011-04-13 13:53:08 +08:00
|
|
|
static int ath9k_htc_choose_bslot(struct ath9k_htc_priv *priv)
|
|
|
|
{
|
|
|
|
struct ath_common *common = ath9k_hw_common(priv->ah);
|
|
|
|
unsigned long flags;
|
|
|
|
u64 tsf;
|
|
|
|
u32 tsftu;
|
|
|
|
u16 intval;
|
|
|
|
int slot;
|
|
|
|
|
|
|
|
intval = priv->cur_beacon_conf.beacon_interval & ATH9K_BEACON_PERIOD;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&priv->wmi->wmi_lock, flags);
|
|
|
|
tsf = priv->wmi->tsf;
|
|
|
|
spin_unlock_irqrestore(&priv->wmi->wmi_lock, flags);
|
|
|
|
|
|
|
|
tsftu = TSF_TO_TU(tsf >> 32, tsf);
|
|
|
|
slot = ((tsftu % intval) * ATH9K_HTC_MAX_BCN_VIF) / intval;
|
|
|
|
slot = ATH9K_HTC_MAX_BCN_VIF - slot - 1;
|
|
|
|
|
|
|
|
ath_dbg(common, ATH_DBG_BEACON,
|
|
|
|
"Choose slot: %d, tsf: %llu, tsftu: %u, intval: %u\n",
|
|
|
|
slot, tsf, tsftu, intval);
|
|
|
|
|
|
|
|
return slot;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ath9k_htc_swba(struct ath9k_htc_priv *priv)
|
|
|
|
{
|
|
|
|
struct ath_common *common = ath9k_hw_common(priv->ah);
|
|
|
|
unsigned long flags;
|
|
|
|
int slot;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&priv->wmi->wmi_lock, flags);
|
|
|
|
if (priv->wmi->beacon_pending != 0) {
|
|
|
|
spin_unlock_irqrestore(&priv->wmi->wmi_lock, flags);
|
|
|
|
priv->cur_beacon_conf.bmiss_cnt++;
|
|
|
|
if (priv->cur_beacon_conf.bmiss_cnt > BSTUCK_THRESHOLD) {
|
|
|
|
ath_dbg(common, ATH_DBG_BEACON,
|
|
|
|
"Beacon stuck, HW reset\n");
|
|
|
|
ath9k_htc_reset(priv);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&priv->wmi->wmi_lock, flags);
|
|
|
|
|
|
|
|
if (priv->cur_beacon_conf.bmiss_cnt) {
|
|
|
|
ath_dbg(common, ATH_DBG_BEACON,
|
|
|
|
"Resuming beacon xmit after %u misses\n",
|
|
|
|
priv->cur_beacon_conf.bmiss_cnt);
|
|
|
|
priv->cur_beacon_conf.bmiss_cnt = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
slot = ath9k_htc_choose_bslot(priv);
|
|
|
|
spin_lock_bh(&priv->beacon_lock);
|
|
|
|
if (priv->cur_beacon_conf.bslot[slot] == NULL) {
|
|
|
|
spin_unlock_bh(&priv->beacon_lock);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
spin_unlock_bh(&priv->beacon_lock);
|
|
|
|
|
2011-04-13 13:53:34 +08:00
|
|
|
ath9k_htc_send_buffered(priv, slot);
|
2011-04-13 13:53:08 +08:00
|
|
|
ath9k_htc_send_beacon(priv, slot);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ath9k_htc_assign_bslot(struct ath9k_htc_priv *priv,
|
|
|
|
struct ieee80211_vif *vif)
|
|
|
|
{
|
|
|
|
struct ath_common *common = ath9k_hw_common(priv->ah);
|
|
|
|
struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *)vif->drv_priv;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
spin_lock_bh(&priv->beacon_lock);
|
|
|
|
for (i = 0; i < ATH9K_HTC_MAX_BCN_VIF; i++) {
|
|
|
|
if (priv->cur_beacon_conf.bslot[i] == NULL) {
|
|
|
|
avp->bslot = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->cur_beacon_conf.bslot[avp->bslot] = vif;
|
|
|
|
spin_unlock_bh(&priv->beacon_lock);
|
|
|
|
|
|
|
|
ath_dbg(common, ATH_DBG_CONFIG,
|
|
|
|
"Added interface at beacon slot: %d\n", avp->bslot);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ath9k_htc_remove_bslot(struct ath9k_htc_priv *priv,
|
|
|
|
struct ieee80211_vif *vif)
|
|
|
|
{
|
|
|
|
struct ath_common *common = ath9k_hw_common(priv->ah);
|
|
|
|
struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *)vif->drv_priv;
|
|
|
|
|
|
|
|
spin_lock_bh(&priv->beacon_lock);
|
|
|
|
priv->cur_beacon_conf.bslot[avp->bslot] = NULL;
|
|
|
|
spin_unlock_bh(&priv->beacon_lock);
|
|
|
|
|
|
|
|
ath_dbg(common, ATH_DBG_CONFIG,
|
|
|
|
"Removed interface at beacon slot: %d\n", avp->bslot);
|
|
|
|
}
|
|
|
|
|
2011-04-13 13:53:17 +08:00
|
|
|
/*
|
|
|
|
* Calculate the TSF adjustment value for all slots
|
|
|
|
* other than zero.
|
|
|
|
*/
|
|
|
|
void ath9k_htc_set_tsfadjust(struct ath9k_htc_priv *priv,
|
|
|
|
struct ieee80211_vif *vif)
|
|
|
|
{
|
|
|
|
struct ath_common *common = ath9k_hw_common(priv->ah);
|
|
|
|
struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *)vif->drv_priv;
|
|
|
|
struct htc_beacon_config *cur_conf = &priv->cur_beacon_conf;
|
|
|
|
u64 tsfadjust;
|
|
|
|
|
|
|
|
if (avp->bslot == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The beacon interval cannot be different for multi-AP mode,
|
|
|
|
* and we reach here only for VIF slots greater than zero,
|
|
|
|
* so beacon_interval is guaranteed to be set in cur_conf.
|
|
|
|
*/
|
|
|
|
tsfadjust = cur_conf->beacon_interval * avp->bslot / ATH9K_HTC_MAX_BCN_VIF;
|
|
|
|
avp->tsfadjust = cpu_to_le64(TU_TO_USEC(tsfadjust));
|
|
|
|
|
|
|
|
ath_dbg(common, ATH_DBG_CONFIG,
|
|
|
|
"tsfadjust is: %llu for bslot: %d\n",
|
|
|
|
(unsigned long long)tsfadjust, avp->bslot);
|
|
|
|
}
|
|
|
|
|
2011-02-27 11:50:40 +08:00
|
|
|
static void ath9k_htc_beacon_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
|
|
|
|
{
|
|
|
|
bool *beacon_configured = (bool *)data;
|
|
|
|
struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
|
|
|
|
|
|
|
|
if (vif->type == NL80211_IFTYPE_STATION &&
|
|
|
|
avp->beacon_configured)
|
|
|
|
*beacon_configured = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool ath9k_htc_check_beacon_config(struct ath9k_htc_priv *priv,
|
|
|
|
struct ieee80211_vif *vif)
|
2010-03-17 16:55:25 +08:00
|
|
|
{
|
|
|
|
struct ath_common *common = ath9k_hw_common(priv->ah);
|
2010-04-05 17:18:06 +08:00
|
|
|
struct htc_beacon_config *cur_conf = &priv->cur_beacon_conf;
|
2010-04-16 14:23:48 +08:00
|
|
|
struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
|
2011-02-27 11:50:40 +08:00
|
|
|
bool beacon_configured;
|
2010-04-05 17:18:06 +08:00
|
|
|
|
2011-02-21 10:19:53 +08:00
|
|
|
/*
|
|
|
|
* Changing the beacon interval when multiple AP interfaces
|
|
|
|
* are configured will affect beacon transmission of all
|
|
|
|
* of them.
|
|
|
|
*/
|
|
|
|
if ((priv->ah->opmode == NL80211_IFTYPE_AP) &&
|
|
|
|
(priv->num_ap_vif > 1) &&
|
|
|
|
(vif->type == NL80211_IFTYPE_AP) &&
|
|
|
|
(cur_conf->beacon_interval != bss_conf->beacon_int)) {
|
|
|
|
ath_dbg(common, ATH_DBG_CONFIG,
|
|
|
|
"Changing beacon interval of multiple AP interfaces !\n");
|
2011-02-27 11:50:40 +08:00
|
|
|
return false;
|
2011-02-21 10:19:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the HW is operating in AP mode, any new station interfaces that
|
|
|
|
* are added cannot change the beacon parameters.
|
|
|
|
*/
|
|
|
|
if (priv->num_ap_vif &&
|
|
|
|
(vif->type != NL80211_IFTYPE_AP)) {
|
|
|
|
ath_dbg(common, ATH_DBG_CONFIG,
|
|
|
|
"HW in AP mode, cannot set STA beacon parameters\n");
|
2011-02-27 11:50:40 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The beacon parameters are configured only for the first
|
|
|
|
* station interface.
|
|
|
|
*/
|
|
|
|
if ((priv->ah->opmode == NL80211_IFTYPE_STATION) &&
|
|
|
|
(priv->num_sta_vif > 1) &&
|
|
|
|
(vif->type == NL80211_IFTYPE_STATION)) {
|
|
|
|
beacon_configured = false;
|
|
|
|
ieee80211_iterate_active_interfaces_atomic(priv->hw,
|
|
|
|
ath9k_htc_beacon_iter,
|
|
|
|
&beacon_configured);
|
|
|
|
|
|
|
|
if (beacon_configured) {
|
|
|
|
ath_dbg(common, ATH_DBG_CONFIG,
|
|
|
|
"Beacon already configured for a station interface\n");
|
|
|
|
return false;
|
|
|
|
}
|
2011-02-21 10:19:53 +08:00
|
|
|
}
|
|
|
|
|
2011-02-27 11:50:40 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ath9k_htc_beacon_config(struct ath9k_htc_priv *priv,
|
|
|
|
struct ieee80211_vif *vif)
|
|
|
|
{
|
|
|
|
struct ath_common *common = ath9k_hw_common(priv->ah);
|
|
|
|
struct htc_beacon_config *cur_conf = &priv->cur_beacon_conf;
|
|
|
|
struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
|
|
|
|
struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
|
|
|
|
|
|
|
|
if (!ath9k_htc_check_beacon_config(priv, vif))
|
|
|
|
return;
|
|
|
|
|
2010-04-16 14:23:48 +08:00
|
|
|
cur_conf->beacon_interval = bss_conf->beacon_int;
|
2010-04-05 17:18:06 +08:00
|
|
|
if (cur_conf->beacon_interval == 0)
|
|
|
|
cur_conf->beacon_interval = 100;
|
|
|
|
|
2010-04-16 14:23:48 +08:00
|
|
|
cur_conf->dtim_period = bss_conf->dtim_period;
|
|
|
|
cur_conf->bmiss_timeout =
|
|
|
|
ATH_DEFAULT_BMISS_LIMIT * cur_conf->beacon_interval;
|
|
|
|
|
|
|
|
switch (vif->type) {
|
2010-03-17 16:55:25 +08:00
|
|
|
case NL80211_IFTYPE_STATION:
|
2010-04-05 17:18:06 +08:00
|
|
|
ath9k_htc_beacon_config_sta(priv, cur_conf);
|
2011-02-27 11:50:40 +08:00
|
|
|
avp->beacon_configured = true;
|
2010-03-17 16:55:25 +08:00
|
|
|
break;
|
|
|
|
case NL80211_IFTYPE_ADHOC:
|
2010-04-05 17:18:06 +08:00
|
|
|
ath9k_htc_beacon_config_adhoc(priv, cur_conf);
|
2010-03-17 16:55:25 +08:00
|
|
|
break;
|
2011-02-21 10:19:53 +08:00
|
|
|
case NL80211_IFTYPE_AP:
|
|
|
|
ath9k_htc_beacon_config_ap(priv, cur_conf);
|
|
|
|
break;
|
2010-03-17 16:55:25 +08:00
|
|
|
default:
|
2010-12-03 11:12:37 +08:00
|
|
|
ath_dbg(common, ATH_DBG_CONFIG,
|
|
|
|
"Unsupported beaconing mode\n");
|
2010-03-17 16:55:25 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2011-02-21 10:18:39 +08:00
|
|
|
|
|
|
|
void ath9k_htc_beacon_reconfig(struct ath9k_htc_priv *priv)
|
|
|
|
{
|
|
|
|
struct ath_common *common = ath9k_hw_common(priv->ah);
|
|
|
|
struct htc_beacon_config *cur_conf = &priv->cur_beacon_conf;
|
|
|
|
|
|
|
|
switch (priv->ah->opmode) {
|
|
|
|
case NL80211_IFTYPE_STATION:
|
|
|
|
ath9k_htc_beacon_config_sta(priv, cur_conf);
|
|
|
|
break;
|
|
|
|
case NL80211_IFTYPE_ADHOC:
|
|
|
|
ath9k_htc_beacon_config_adhoc(priv, cur_conf);
|
|
|
|
break;
|
2011-02-21 10:19:53 +08:00
|
|
|
case NL80211_IFTYPE_AP:
|
|
|
|
ath9k_htc_beacon_config_ap(priv, cur_conf);
|
|
|
|
break;
|
2011-02-21 10:18:39 +08:00
|
|
|
default:
|
|
|
|
ath_dbg(common, ATH_DBG_CONFIG,
|
|
|
|
"Unsupported beaconing mode\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|