1 /* 2 * Copyright (c) 2010-2011 Atheros Communications Inc. 3 * 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. 7 * 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. 15 */ 16 17 #include "htc.h" 18 19 #define FUDGE 2 20 21 void ath9k_htc_beaconq_config(struct ath9k_htc_priv *priv) 22 { 23 struct ath_hw *ah = priv->ah; 24 struct ath9k_tx_queue_info qi, qi_be; 25 26 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info)); 27 memset(&qi_be, 0, sizeof(struct ath9k_tx_queue_info)); 28 29 ath9k_hw_get_txq_props(ah, priv->beaconq, &qi); 30 31 if (priv->ah->opmode == NL80211_IFTYPE_AP || 32 priv->ah->opmode == NL80211_IFTYPE_MESH_POINT) { 33 qi.tqi_aifs = 1; 34 qi.tqi_cwmin = 0; 35 qi.tqi_cwmax = 0; 36 } else if (priv->ah->opmode == NL80211_IFTYPE_ADHOC) { 37 int qnum = priv->hwq_map[IEEE80211_AC_BE]; 38 39 ath9k_hw_get_txq_props(ah, qnum, &qi_be); 40 41 qi.tqi_aifs = qi_be.tqi_aifs; 42 43 /* 44 * For WIFI Beacon Distribution 45 * Long slot time : 2x cwmin 46 * Short slot time : 4x cwmin 47 */ 48 if (ah->slottime == ATH9K_SLOT_TIME_20) 49 qi.tqi_cwmin = 2*qi_be.tqi_cwmin; 50 else 51 qi.tqi_cwmin = 4*qi_be.tqi_cwmin; 52 53 qi.tqi_cwmax = qi_be.tqi_cwmax; 54 55 } 56 57 if (!ath9k_hw_set_txq_props(ah, priv->beaconq, &qi)) { 58 ath_err(ath9k_hw_common(ah), 59 "Unable to update beacon queue %u!\n", priv->beaconq); 60 } else { 61 ath9k_hw_resettxqueue(ah, priv->beaconq); 62 } 63 } 64 65 66 static void ath9k_htc_beacon_config_sta(struct ath9k_htc_priv *priv, 67 struct htc_beacon_config *bss_conf) 68 { 69 struct ath_common *common = ath9k_hw_common(priv->ah); 70 struct ath9k_beacon_state bs; 71 enum ath9k_int imask = 0; 72 int dtimperiod, dtimcount, sleepduration; 73 int bmiss_timeout; 74 u32 nexttbtt = 0, intval, tsftu; 75 __be32 htc_imask = 0; 76 u64 tsf; 77 int num_beacons, offset, dtim_dec_count; 78 int ret __attribute__ ((unused)); 79 u8 cmd_rsp; 80 81 memset(&bs, 0, sizeof(bs)); 82 83 intval = bss_conf->beacon_interval; 84 bmiss_timeout = (ATH_DEFAULT_BMISS_LIMIT * bss_conf->beacon_interval); 85 86 /* 87 * Setup dtim parameters according to 88 * last beacon we received (which may be none). 89 */ 90 dtimperiod = bss_conf->dtim_period; 91 if (dtimperiod <= 0) /* NB: 0 if not known */ 92 dtimperiod = 1; 93 dtimcount = 1; 94 if (dtimcount >= dtimperiod) /* NB: sanity check */ 95 dtimcount = 0; 96 97 sleepduration = intval; 98 if (sleepduration <= 0) 99 sleepduration = intval; 100 101 /* 102 * Pull nexttbtt forward to reflect the current 103 * TSF and calculate dtim state for the result. 104 */ 105 tsf = ath9k_hw_gettsf64(priv->ah); 106 tsftu = TSF_TO_TU(tsf>>32, tsf) + FUDGE; 107 108 num_beacons = tsftu / intval + 1; 109 offset = tsftu % intval; 110 nexttbtt = tsftu - offset; 111 if (offset) 112 nexttbtt += intval; 113 114 /* DTIM Beacon every dtimperiod Beacon */ 115 dtim_dec_count = num_beacons % dtimperiod; 116 dtimcount -= dtim_dec_count; 117 if (dtimcount < 0) 118 dtimcount += dtimperiod; 119 120 bs.bs_intval = TU_TO_USEC(intval); 121 bs.bs_nexttbtt = TU_TO_USEC(nexttbtt); 122 bs.bs_dtimperiod = dtimperiod * bs.bs_intval; 123 bs.bs_nextdtim = bs.bs_nexttbtt + dtimcount * bs.bs_intval; 124 125 /* 126 * Calculate the number of consecutive beacons to miss* before taking 127 * a BMISS interrupt. The configuration is specified in TU so we only 128 * need calculate based on the beacon interval. Note that we clamp the 129 * result to at most 15 beacons. 130 */ 131 if (sleepduration > intval) { 132 bs.bs_bmissthreshold = ATH_DEFAULT_BMISS_LIMIT / 2; 133 } else { 134 bs.bs_bmissthreshold = DIV_ROUND_UP(bmiss_timeout, intval); 135 if (bs.bs_bmissthreshold > 15) 136 bs.bs_bmissthreshold = 15; 137 else if (bs.bs_bmissthreshold <= 0) 138 bs.bs_bmissthreshold = 1; 139 } 140 141 /* 142 * Calculate sleep duration. The configuration is given in ms. 143 * We ensure a multiple of the beacon period is used. Also, if the sleep 144 * duration is greater than the DTIM period then it makes senses 145 * to make it a multiple of that. 146 * 147 * XXX fixed at 100ms 148 */ 149 150 bs.bs_sleepduration = TU_TO_USEC(roundup(IEEE80211_MS_TO_TU(100), 151 sleepduration)); 152 if (bs.bs_sleepduration > bs.bs_dtimperiod) 153 bs.bs_sleepduration = bs.bs_dtimperiod; 154 155 /* TSF out of range threshold fixed at 1 second */ 156 bs.bs_tsfoor_threshold = ATH9K_TSFOOR_THRESHOLD; 157 158 ath_dbg(common, CONFIG, "intval: %u tsf: %llu tsftu: %u\n", 159 intval, tsf, tsftu); 160 ath_dbg(common, CONFIG, "bmiss: %u sleep: %u\n", 161 bs.bs_bmissthreshold, bs.bs_sleepduration); 162 163 /* Set the computed STA beacon timers */ 164 165 WMI_CMD(WMI_DISABLE_INTR_CMDID); 166 ath9k_hw_set_sta_beacon_timers(priv->ah, &bs); 167 imask |= ATH9K_INT_BMISS; 168 htc_imask = cpu_to_be32(imask); 169 WMI_CMD_BUF(WMI_ENABLE_INTR_CMDID, &htc_imask); 170 } 171 172 static void ath9k_htc_beacon_config_ap(struct ath9k_htc_priv *priv, 173 struct htc_beacon_config *bss_conf) 174 { 175 struct ath_common *common = ath9k_hw_common(priv->ah); 176 enum ath9k_int imask = 0; 177 u32 nexttbtt, intval, tsftu; 178 __be32 htc_imask = 0; 179 int ret __attribute__ ((unused)); 180 u8 cmd_rsp; 181 u64 tsf; 182 183 intval = bss_conf->beacon_interval; 184 intval /= ATH9K_HTC_MAX_BCN_VIF; 185 nexttbtt = intval; 186 187 /* 188 * To reduce beacon misses under heavy TX load, 189 * set the beacon response time to a larger value. 190 */ 191 if (intval > DEFAULT_SWBA_RESPONSE) 192 priv->ah->config.sw_beacon_response_time = DEFAULT_SWBA_RESPONSE; 193 else 194 priv->ah->config.sw_beacon_response_time = MIN_SWBA_RESPONSE; 195 196 if (test_bit(OP_TSF_RESET, &priv->op_flags)) { 197 ath9k_hw_reset_tsf(priv->ah); 198 clear_bit(OP_TSF_RESET, &priv->op_flags); 199 } else { 200 /* 201 * Pull nexttbtt forward to reflect the current TSF. 202 */ 203 tsf = ath9k_hw_gettsf64(priv->ah); 204 tsftu = TSF_TO_TU(tsf >> 32, tsf) + FUDGE; 205 do { 206 nexttbtt += intval; 207 } while (nexttbtt < tsftu); 208 } 209 210 if (test_bit(OP_ENABLE_BEACON, &priv->op_flags)) 211 imask |= ATH9K_INT_SWBA; 212 213 ath_dbg(common, CONFIG, 214 "AP Beacon config, intval: %d, nexttbtt: %u, resp_time: %d imask: 0x%x\n", 215 bss_conf->beacon_interval, nexttbtt, 216 priv->ah->config.sw_beacon_response_time, imask); 217 218 ath9k_htc_beaconq_config(priv); 219 220 WMI_CMD(WMI_DISABLE_INTR_CMDID); 221 ath9k_hw_beaconinit(priv->ah, TU_TO_USEC(nexttbtt), TU_TO_USEC(intval)); 222 priv->cur_beacon_conf.bmiss_cnt = 0; 223 htc_imask = cpu_to_be32(imask); 224 WMI_CMD_BUF(WMI_ENABLE_INTR_CMDID, &htc_imask); 225 } 226 227 static void ath9k_htc_beacon_config_adhoc(struct ath9k_htc_priv *priv, 228 struct htc_beacon_config *bss_conf) 229 { 230 struct ath_common *common = ath9k_hw_common(priv->ah); 231 enum ath9k_int imask = 0; 232 u32 nexttbtt, intval, tsftu; 233 __be32 htc_imask = 0; 234 int ret __attribute__ ((unused)); 235 u8 cmd_rsp; 236 u64 tsf; 237 238 intval = bss_conf->beacon_interval; 239 nexttbtt = intval; 240 241 /* 242 * Pull nexttbtt forward to reflect the current TSF. 243 */ 244 tsf = ath9k_hw_gettsf64(priv->ah); 245 tsftu = TSF_TO_TU(tsf >> 32, tsf) + FUDGE; 246 do { 247 nexttbtt += intval; 248 } while (nexttbtt < tsftu); 249 250 /* 251 * Only one IBSS interfce is allowed. 252 */ 253 if (intval > DEFAULT_SWBA_RESPONSE) 254 priv->ah->config.sw_beacon_response_time = DEFAULT_SWBA_RESPONSE; 255 else 256 priv->ah->config.sw_beacon_response_time = MIN_SWBA_RESPONSE; 257 258 if (test_bit(OP_ENABLE_BEACON, &priv->op_flags)) 259 imask |= ATH9K_INT_SWBA; 260 261 ath_dbg(common, CONFIG, 262 "IBSS Beacon config, intval: %d, nexttbtt: %u, resp_time: %d, imask: 0x%x\n", 263 bss_conf->beacon_interval, nexttbtt, 264 priv->ah->config.sw_beacon_response_time, imask); 265 266 WMI_CMD(WMI_DISABLE_INTR_CMDID); 267 ath9k_hw_beaconinit(priv->ah, TU_TO_USEC(nexttbtt), TU_TO_USEC(intval)); 268 priv->cur_beacon_conf.bmiss_cnt = 0; 269 htc_imask = cpu_to_be32(imask); 270 WMI_CMD_BUF(WMI_ENABLE_INTR_CMDID, &htc_imask); 271 } 272 273 void ath9k_htc_beaconep(void *drv_priv, struct sk_buff *skb, 274 enum htc_endpoint_id ep_id, bool txok) 275 { 276 dev_kfree_skb_any(skb); 277 } 278 279 static void ath9k_htc_send_buffered(struct ath9k_htc_priv *priv, 280 int slot) 281 { 282 struct ath_common *common = ath9k_hw_common(priv->ah); 283 struct ieee80211_vif *vif; 284 struct sk_buff *skb; 285 struct ieee80211_hdr *hdr; 286 int padpos, padsize, ret, tx_slot; 287 288 spin_lock_bh(&priv->beacon_lock); 289 290 vif = priv->cur_beacon_conf.bslot[slot]; 291 292 skb = ieee80211_get_buffered_bc(priv->hw, vif); 293 294 while(skb) { 295 hdr = (struct ieee80211_hdr *) skb->data; 296 297 padpos = ieee80211_hdrlen(hdr->frame_control); 298 padsize = padpos & 3; 299 if (padsize && skb->len > padpos) { 300 if (skb_headroom(skb) < padsize) { 301 dev_kfree_skb_any(skb); 302 goto next; 303 } 304 skb_push(skb, padsize); 305 memmove(skb->data, skb->data + padsize, padpos); 306 } 307 308 tx_slot = ath9k_htc_tx_get_slot(priv); 309 if (tx_slot < 0) { 310 ath_dbg(common, XMIT, "No free CAB slot\n"); 311 dev_kfree_skb_any(skb); 312 goto next; 313 } 314 315 ret = ath9k_htc_tx_start(priv, NULL, skb, tx_slot, true); 316 if (ret != 0) { 317 ath9k_htc_tx_clear_slot(priv, tx_slot); 318 dev_kfree_skb_any(skb); 319 320 ath_dbg(common, XMIT, "Failed to send CAB frame\n"); 321 } else { 322 spin_lock_bh(&priv->tx.tx_lock); 323 priv->tx.queued_cnt++; 324 spin_unlock_bh(&priv->tx.tx_lock); 325 } 326 next: 327 skb = ieee80211_get_buffered_bc(priv->hw, vif); 328 } 329 330 spin_unlock_bh(&priv->beacon_lock); 331 } 332 333 static void ath9k_htc_send_beacon(struct ath9k_htc_priv *priv, 334 int slot) 335 { 336 struct ath_common *common = ath9k_hw_common(priv->ah); 337 struct ieee80211_vif *vif; 338 struct ath9k_htc_vif *avp; 339 struct tx_beacon_header beacon_hdr; 340 struct ath9k_htc_tx_ctl *tx_ctl; 341 struct ieee80211_tx_info *info; 342 struct ieee80211_mgmt *mgmt; 343 struct sk_buff *beacon; 344 u8 *tx_fhdr; 345 int ret; 346 347 memset(&beacon_hdr, 0, sizeof(struct tx_beacon_header)); 348 349 spin_lock_bh(&priv->beacon_lock); 350 351 vif = priv->cur_beacon_conf.bslot[slot]; 352 avp = (struct ath9k_htc_vif *)vif->drv_priv; 353 354 if (unlikely(test_bit(OP_SCANNING, &priv->op_flags))) { 355 spin_unlock_bh(&priv->beacon_lock); 356 return; 357 } 358 359 /* Get a new beacon */ 360 beacon = ieee80211_beacon_get(priv->hw, vif); 361 if (!beacon) { 362 spin_unlock_bh(&priv->beacon_lock); 363 return; 364 } 365 366 /* 367 * Update the TSF adjust value here, the HW will 368 * add this value for every beacon. 369 */ 370 mgmt = (struct ieee80211_mgmt *)beacon->data; 371 mgmt->u.beacon.timestamp = avp->tsfadjust; 372 373 info = IEEE80211_SKB_CB(beacon); 374 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) { 375 struct ieee80211_hdr *hdr = 376 (struct ieee80211_hdr *) beacon->data; 377 avp->seq_no += 0x10; 378 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG); 379 hdr->seq_ctrl |= cpu_to_le16(avp->seq_no); 380 } 381 382 tx_ctl = HTC_SKB_CB(beacon); 383 memset(tx_ctl, 0, sizeof(*tx_ctl)); 384 385 tx_ctl->type = ATH9K_HTC_BEACON; 386 tx_ctl->epid = priv->beacon_ep; 387 388 beacon_hdr.vif_index = avp->index; 389 tx_fhdr = skb_push(beacon, sizeof(beacon_hdr)); 390 memcpy(tx_fhdr, (u8 *) &beacon_hdr, sizeof(beacon_hdr)); 391 392 ret = htc_send(priv->htc, beacon); 393 if (ret != 0) { 394 if (ret == -ENOMEM) { 395 ath_dbg(common, BSTUCK, 396 "Failed to send beacon, no free TX buffer\n"); 397 } 398 dev_kfree_skb_any(beacon); 399 } 400 401 spin_unlock_bh(&priv->beacon_lock); 402 } 403 404 static int ath9k_htc_choose_bslot(struct ath9k_htc_priv *priv, 405 struct wmi_event_swba *swba) 406 { 407 struct ath_common *common = ath9k_hw_common(priv->ah); 408 u64 tsf; 409 u32 tsftu; 410 u16 intval; 411 int slot; 412 413 intval = priv->cur_beacon_conf.beacon_interval; 414 415 tsf = be64_to_cpu(swba->tsf); 416 tsftu = TSF_TO_TU(tsf >> 32, tsf); 417 slot = ((tsftu % intval) * ATH9K_HTC_MAX_BCN_VIF) / intval; 418 slot = ATH9K_HTC_MAX_BCN_VIF - slot - 1; 419 420 ath_dbg(common, BEACON, 421 "Choose slot: %d, tsf: %llu, tsftu: %u, intval: %u\n", 422 slot, tsf, tsftu, intval); 423 424 return slot; 425 } 426 427 void ath9k_htc_swba(struct ath9k_htc_priv *priv, 428 struct wmi_event_swba *swba) 429 { 430 struct ath_common *common = ath9k_hw_common(priv->ah); 431 int slot; 432 433 if (swba->beacon_pending != 0) { 434 priv->cur_beacon_conf.bmiss_cnt++; 435 if (priv->cur_beacon_conf.bmiss_cnt > BSTUCK_THRESHOLD) { 436 ath_dbg(common, BSTUCK, "Beacon stuck, HW reset\n"); 437 ieee80211_queue_work(priv->hw, 438 &priv->fatal_work); 439 } 440 return; 441 } 442 443 if (priv->cur_beacon_conf.bmiss_cnt) { 444 ath_dbg(common, BSTUCK, 445 "Resuming beacon xmit after %u misses\n", 446 priv->cur_beacon_conf.bmiss_cnt); 447 priv->cur_beacon_conf.bmiss_cnt = 0; 448 } 449 450 slot = ath9k_htc_choose_bslot(priv, swba); 451 spin_lock_bh(&priv->beacon_lock); 452 if (priv->cur_beacon_conf.bslot[slot] == NULL) { 453 spin_unlock_bh(&priv->beacon_lock); 454 return; 455 } 456 spin_unlock_bh(&priv->beacon_lock); 457 458 ath9k_htc_send_buffered(priv, slot); 459 ath9k_htc_send_beacon(priv, slot); 460 } 461 462 void ath9k_htc_assign_bslot(struct ath9k_htc_priv *priv, 463 struct ieee80211_vif *vif) 464 { 465 struct ath_common *common = ath9k_hw_common(priv->ah); 466 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *)vif->drv_priv; 467 int i = 0; 468 469 spin_lock_bh(&priv->beacon_lock); 470 for (i = 0; i < ATH9K_HTC_MAX_BCN_VIF; i++) { 471 if (priv->cur_beacon_conf.bslot[i] == NULL) { 472 avp->bslot = i; 473 break; 474 } 475 } 476 477 priv->cur_beacon_conf.bslot[avp->bslot] = vif; 478 spin_unlock_bh(&priv->beacon_lock); 479 480 ath_dbg(common, CONFIG, "Added interface at beacon slot: %d\n", 481 avp->bslot); 482 } 483 484 void ath9k_htc_remove_bslot(struct ath9k_htc_priv *priv, 485 struct ieee80211_vif *vif) 486 { 487 struct ath_common *common = ath9k_hw_common(priv->ah); 488 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *)vif->drv_priv; 489 490 spin_lock_bh(&priv->beacon_lock); 491 priv->cur_beacon_conf.bslot[avp->bslot] = NULL; 492 spin_unlock_bh(&priv->beacon_lock); 493 494 ath_dbg(common, CONFIG, "Removed interface at beacon slot: %d\n", 495 avp->bslot); 496 } 497 498 /* 499 * Calculate the TSF adjustment value for all slots 500 * other than zero. 501 */ 502 void ath9k_htc_set_tsfadjust(struct ath9k_htc_priv *priv, 503 struct ieee80211_vif *vif) 504 { 505 struct ath_common *common = ath9k_hw_common(priv->ah); 506 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *)vif->drv_priv; 507 struct htc_beacon_config *cur_conf = &priv->cur_beacon_conf; 508 u64 tsfadjust; 509 510 if (avp->bslot == 0) 511 return; 512 513 /* 514 * The beacon interval cannot be different for multi-AP mode, 515 * and we reach here only for VIF slots greater than zero, 516 * so beacon_interval is guaranteed to be set in cur_conf. 517 */ 518 tsfadjust = cur_conf->beacon_interval * avp->bslot / ATH9K_HTC_MAX_BCN_VIF; 519 avp->tsfadjust = cpu_to_le64(TU_TO_USEC(tsfadjust)); 520 521 ath_dbg(common, CONFIG, "tsfadjust is: %llu for bslot: %d\n", 522 (unsigned long long)tsfadjust, avp->bslot); 523 } 524 525 static void ath9k_htc_beacon_iter(void *data, u8 *mac, struct ieee80211_vif *vif) 526 { 527 bool *beacon_configured = (bool *)data; 528 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv; 529 530 if (vif->type == NL80211_IFTYPE_STATION && 531 avp->beacon_configured) 532 *beacon_configured = true; 533 } 534 535 static bool ath9k_htc_check_beacon_config(struct ath9k_htc_priv *priv, 536 struct ieee80211_vif *vif) 537 { 538 struct ath_common *common = ath9k_hw_common(priv->ah); 539 struct htc_beacon_config *cur_conf = &priv->cur_beacon_conf; 540 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; 541 bool beacon_configured; 542 543 /* 544 * Changing the beacon interval when multiple AP interfaces 545 * are configured will affect beacon transmission of all 546 * of them. 547 */ 548 if ((priv->ah->opmode == NL80211_IFTYPE_AP) && 549 (priv->num_ap_vif > 1) && 550 (vif->type == NL80211_IFTYPE_AP) && 551 (cur_conf->beacon_interval != bss_conf->beacon_int)) { 552 ath_dbg(common, CONFIG, 553 "Changing beacon interval of multiple AP interfaces !\n"); 554 return false; 555 } 556 557 /* 558 * If the HW is operating in AP mode, any new station interfaces that 559 * are added cannot change the beacon parameters. 560 */ 561 if (priv->num_ap_vif && 562 (vif->type != NL80211_IFTYPE_AP)) { 563 ath_dbg(common, CONFIG, 564 "HW in AP mode, cannot set STA beacon parameters\n"); 565 return false; 566 } 567 568 /* 569 * The beacon parameters are configured only for the first 570 * station interface. 571 */ 572 if ((priv->ah->opmode == NL80211_IFTYPE_STATION) && 573 (priv->num_sta_vif > 1) && 574 (vif->type == NL80211_IFTYPE_STATION)) { 575 beacon_configured = false; 576 ieee80211_iterate_active_interfaces_atomic( 577 priv->hw, IEEE80211_IFACE_ITER_RESUME_ALL, 578 ath9k_htc_beacon_iter, &beacon_configured); 579 580 if (beacon_configured) { 581 ath_dbg(common, CONFIG, 582 "Beacon already configured for a station interface\n"); 583 return false; 584 } 585 } 586 587 return true; 588 } 589 590 void ath9k_htc_beacon_config(struct ath9k_htc_priv *priv, 591 struct ieee80211_vif *vif) 592 { 593 struct ath_common *common = ath9k_hw_common(priv->ah); 594 struct htc_beacon_config *cur_conf = &priv->cur_beacon_conf; 595 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; 596 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv; 597 598 if (!ath9k_htc_check_beacon_config(priv, vif)) 599 return; 600 601 cur_conf->beacon_interval = bss_conf->beacon_int; 602 if (cur_conf->beacon_interval == 0) 603 cur_conf->beacon_interval = 100; 604 605 cur_conf->dtim_period = bss_conf->dtim_period; 606 cur_conf->bmiss_timeout = 607 ATH_DEFAULT_BMISS_LIMIT * cur_conf->beacon_interval; 608 609 switch (vif->type) { 610 case NL80211_IFTYPE_STATION: 611 ath9k_htc_beacon_config_sta(priv, cur_conf); 612 avp->beacon_configured = true; 613 break; 614 case NL80211_IFTYPE_ADHOC: 615 ath9k_htc_beacon_config_adhoc(priv, cur_conf); 616 break; 617 case NL80211_IFTYPE_MESH_POINT: 618 case NL80211_IFTYPE_AP: 619 ath9k_htc_beacon_config_ap(priv, cur_conf); 620 break; 621 default: 622 ath_dbg(common, CONFIG, "Unsupported beaconing mode\n"); 623 return; 624 } 625 } 626 627 void ath9k_htc_beacon_reconfig(struct ath9k_htc_priv *priv) 628 { 629 struct ath_common *common = ath9k_hw_common(priv->ah); 630 struct htc_beacon_config *cur_conf = &priv->cur_beacon_conf; 631 632 switch (priv->ah->opmode) { 633 case NL80211_IFTYPE_STATION: 634 ath9k_htc_beacon_config_sta(priv, cur_conf); 635 break; 636 case NL80211_IFTYPE_ADHOC: 637 ath9k_htc_beacon_config_adhoc(priv, cur_conf); 638 break; 639 case NL80211_IFTYPE_MESH_POINT: 640 case NL80211_IFTYPE_AP: 641 ath9k_htc_beacon_config_ap(priv, cur_conf); 642 break; 643 default: 644 ath_dbg(common, CONFIG, "Unsupported beaconing mode\n"); 645 return; 646 } 647 } 648