GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / net / wireless / ath / ath9k / htc_drv_beacon.c
blobc30c40d5aafa1c6575f340e542834f0fef12cb65
1 /*
2 * Copyright (c) 2010 Atheros Communications Inc.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #include "htc.h"
19 #define FUDGE 2
21 static void ath9k_htc_beacon_config_sta(struct ath9k_htc_priv *priv,
22 struct htc_beacon_config *bss_conf)
24 struct ath_common *common = ath9k_hw_common(priv->ah);
25 struct ath9k_beacon_state bs;
26 enum ath9k_int imask = 0;
27 int dtimperiod, dtimcount, sleepduration;
28 int cfpperiod, cfpcount, bmiss_timeout;
29 u32 nexttbtt = 0, intval, tsftu;
30 __be32 htc_imask = 0;
31 u64 tsf;
32 int num_beacons, offset, dtim_dec_count, cfp_dec_count;
33 int ret;
34 u8 cmd_rsp;
36 memset(&bs, 0, sizeof(bs));
38 intval = bss_conf->beacon_interval & ATH9K_BEACON_PERIOD;
39 bmiss_timeout = (ATH_DEFAULT_BMISS_LIMIT * bss_conf->beacon_interval);
42 * Setup dtim and cfp parameters according to
43 * last beacon we received (which may be none).
45 dtimperiod = bss_conf->dtim_period;
46 if (dtimperiod <= 0) /* NB: 0 if not known */
47 dtimperiod = 1;
48 dtimcount = 1;
49 if (dtimcount >= dtimperiod) /* NB: sanity check */
50 dtimcount = 0;
51 cfpperiod = 1; /* NB: no PCF support yet */
52 cfpcount = 0;
54 sleepduration = intval;
55 if (sleepduration <= 0)
56 sleepduration = intval;
59 * Pull nexttbtt forward to reflect the current
60 * TSF and calculate dtim+cfp state for the result.
62 tsf = ath9k_hw_gettsf64(priv->ah);
63 tsftu = TSF_TO_TU(tsf>>32, tsf) + FUDGE;
65 num_beacons = tsftu / intval + 1;
66 offset = tsftu % intval;
67 nexttbtt = tsftu - offset;
68 if (offset)
69 nexttbtt += intval;
71 /* DTIM Beacon every dtimperiod Beacon */
72 dtim_dec_count = num_beacons % dtimperiod;
73 /* CFP every cfpperiod DTIM Beacon */
74 cfp_dec_count = (num_beacons / dtimperiod) % cfpperiod;
75 if (dtim_dec_count)
76 cfp_dec_count++;
78 dtimcount -= dtim_dec_count;
79 if (dtimcount < 0)
80 dtimcount += dtimperiod;
82 cfpcount -= cfp_dec_count;
83 if (cfpcount < 0)
84 cfpcount += cfpperiod;
86 bs.bs_intval = intval;
87 bs.bs_nexttbtt = nexttbtt;
88 bs.bs_dtimperiod = dtimperiod*intval;
89 bs.bs_nextdtim = bs.bs_nexttbtt + dtimcount*intval;
90 bs.bs_cfpperiod = cfpperiod*bs.bs_dtimperiod;
91 bs.bs_cfpnext = bs.bs_nextdtim + cfpcount*bs.bs_dtimperiod;
92 bs.bs_cfpmaxduration = 0;
95 * Calculate the number of consecutive beacons to miss* before taking
96 * a BMISS interrupt. The configuration is specified in TU so we only
97 * need calculate based on the beacon interval. Note that we clamp the
98 * result to at most 15 beacons.
100 if (sleepduration > intval) {
101 bs.bs_bmissthreshold = ATH_DEFAULT_BMISS_LIMIT / 2;
102 } else {
103 bs.bs_bmissthreshold = DIV_ROUND_UP(bmiss_timeout, intval);
104 if (bs.bs_bmissthreshold > 15)
105 bs.bs_bmissthreshold = 15;
106 else if (bs.bs_bmissthreshold <= 0)
107 bs.bs_bmissthreshold = 1;
111 bs.bs_sleepduration = roundup(IEEE80211_MS_TO_TU(100), sleepduration);
112 if (bs.bs_sleepduration > bs.bs_dtimperiod)
113 bs.bs_sleepduration = bs.bs_dtimperiod;
115 /* TSF out of range threshold fixed at 1 second */
116 bs.bs_tsfoor_threshold = ATH9K_TSFOOR_THRESHOLD;
118 ath_print(common, ATH_DBG_BEACON, "tsf: %llu tsftu: %u\n", tsf, tsftu);
119 ath_print(common, ATH_DBG_BEACON,
120 "bmiss: %u sleep: %u cfp-period: %u maxdur: %u next: %u\n",
121 bs.bs_bmissthreshold, bs.bs_sleepduration,
122 bs.bs_cfpperiod, bs.bs_cfpmaxduration, bs.bs_cfpnext);
124 /* Set the computed STA beacon timers */
126 WMI_CMD(WMI_DISABLE_INTR_CMDID);
127 ath9k_hw_set_sta_beacon_timers(priv->ah, &bs);
128 imask |= ATH9K_INT_BMISS;
129 htc_imask = cpu_to_be32(imask);
130 WMI_CMD_BUF(WMI_ENABLE_INTR_CMDID, &htc_imask);
133 static void ath9k_htc_beacon_config_adhoc(struct ath9k_htc_priv *priv,
134 struct htc_beacon_config *bss_conf)
136 struct ath_common *common = ath9k_hw_common(priv->ah);
137 enum ath9k_int imask = 0;
138 u32 nexttbtt, intval;
139 __be32 htc_imask = 0;
140 int ret;
141 u8 cmd_rsp;
143 intval = bss_conf->beacon_interval & ATH9K_BEACON_PERIOD;
144 nexttbtt = intval;
145 intval |= ATH9K_BEACON_ENA;
146 if (priv->op_flags & OP_ENABLE_BEACON)
147 imask |= ATH9K_INT_SWBA;
149 ath_print(common, ATH_DBG_BEACON,
150 "IBSS Beacon config, intval: %d, imask: 0x%x\n",
151 bss_conf->beacon_interval, imask);
153 WMI_CMD(WMI_DISABLE_INTR_CMDID);
154 ath9k_hw_beaconinit(priv->ah, nexttbtt, intval);
155 priv->bmiss_cnt = 0;
156 htc_imask = cpu_to_be32(imask);
157 WMI_CMD_BUF(WMI_ENABLE_INTR_CMDID, &htc_imask);
160 void ath9k_htc_beaconep(void *drv_priv, struct sk_buff *skb,
161 enum htc_endpoint_id ep_id, bool txok)
163 dev_kfree_skb_any(skb);
166 void ath9k_htc_swba(struct ath9k_htc_priv *priv, u8 beacon_pending)
168 struct ath9k_htc_vif *avp = (void *)priv->vif->drv_priv;
169 struct tx_beacon_header beacon_hdr;
170 struct ath9k_htc_tx_ctl tx_ctl;
171 struct ieee80211_tx_info *info;
172 struct sk_buff *beacon;
173 u8 *tx_fhdr;
175 memset(&beacon_hdr, 0, sizeof(struct tx_beacon_header));
176 memset(&tx_ctl, 0, sizeof(struct ath9k_htc_tx_ctl));
178 if (beacon_pending != 0) {
179 priv->bmiss_cnt++;
180 return;
183 spin_lock_bh(&priv->beacon_lock);
185 if (unlikely(priv->op_flags & OP_SCANNING)) {
186 spin_unlock_bh(&priv->beacon_lock);
187 return;
190 /* Get a new beacon */
191 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
192 if (!beacon) {
193 spin_unlock_bh(&priv->beacon_lock);
194 return;
197 info = IEEE80211_SKB_CB(beacon);
198 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
199 struct ieee80211_hdr *hdr =
200 (struct ieee80211_hdr *) beacon->data;
201 priv->seq_no += 0x10;
202 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
203 hdr->seq_ctrl |= cpu_to_le16(priv->seq_no);
206 tx_ctl.type = ATH9K_HTC_NORMAL;
207 beacon_hdr.vif_index = avp->index;
208 tx_fhdr = skb_push(beacon, sizeof(beacon_hdr));
209 memcpy(tx_fhdr, (u8 *) &beacon_hdr, sizeof(beacon_hdr));
211 htc_send(priv->htc, beacon, priv->beacon_ep, &tx_ctl);
213 spin_unlock_bh(&priv->beacon_lock);
216 /* Currently, only for IBSS */
217 void ath9k_htc_beaconq_config(struct ath9k_htc_priv *priv)
219 struct ath_hw *ah = priv->ah;
220 struct ath9k_tx_queue_info qi, qi_be;
221 int qnum = priv->hwq_map[WME_AC_BE];
223 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
224 memset(&qi_be, 0, sizeof(struct ath9k_tx_queue_info));
226 ath9k_hw_get_txq_props(ah, qnum, &qi_be);
228 qi.tqi_aifs = qi_be.tqi_aifs;
229 qi.tqi_cwmin = 4*qi_be.tqi_cwmin;
230 qi.tqi_cwmax = qi_be.tqi_cwmax;
232 if (!ath9k_hw_set_txq_props(ah, priv->beaconq, &qi)) {
233 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
234 "Unable to update beacon queue %u!\n", qnum);
235 } else {
236 ath9k_hw_resettxqueue(ah, priv->beaconq);
240 void ath9k_htc_beacon_config(struct ath9k_htc_priv *priv,
241 struct ieee80211_vif *vif)
243 struct ath_common *common = ath9k_hw_common(priv->ah);
244 struct htc_beacon_config *cur_conf = &priv->cur_beacon_conf;
245 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
247 cur_conf->beacon_interval = bss_conf->beacon_int;
248 if (cur_conf->beacon_interval == 0)
249 cur_conf->beacon_interval = 100;
251 cur_conf->dtim_period = bss_conf->dtim_period;
252 cur_conf->listen_interval = 1;
253 cur_conf->dtim_count = 1;
254 cur_conf->bmiss_timeout =
255 ATH_DEFAULT_BMISS_LIMIT * cur_conf->beacon_interval;
257 switch (vif->type) {
258 case NL80211_IFTYPE_STATION:
259 ath9k_htc_beacon_config_sta(priv, cur_conf);
260 break;
261 case NL80211_IFTYPE_ADHOC:
262 ath9k_htc_beacon_config_adhoc(priv, cur_conf);
263 break;
264 default:
265 ath_print(common, ATH_DBG_CONFIG,
266 "Unsupported beaconing mode\n");
267 return;