1 /*- 2 * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting 3 * Copyright (c) 2004-2005 Atheros Communications, Inc. 4 * Copyright (c) 2006 Devicescape Software, Inc. 5 * Copyright (c) 2007 Jiri Slaby <jirislaby@gmail.com> 6 * Copyright (c) 2007 Luis R. Rodriguez <mcgrof@winlab.rutgers.edu> 7 * Copyright (c) 2010 Bruno Randolf <br1@einfach.org> 8 * 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer, 16 * without modification. 17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any 19 * redistribution must be conditioned upon including a substantially 20 * similar Disclaimer requirement for further binary redistribution. 21 * 3. Neither the names of the above-listed copyright holders nor the names 22 * of any contributors may be used to endorse or promote products derived 23 * from this software without specific prior written permission. 24 * 25 * Alternatively, this software may be distributed under the terms of the 26 * GNU General Public License ("GPL") version 2 as published by the Free 27 * Software Foundation. 28 * 29 * NO WARRANTY 30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 31 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 32 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY 33 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 34 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, 35 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 36 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 37 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 38 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 39 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 40 * THE POSSIBILITY OF SUCH DAMAGES. 41 * 42 */ 43 44 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 45 46 #include <net/mac80211.h> 47 #include <asm/unaligned.h> 48 49 #include "ath5k.h" 50 #include "base.h" 51 #include "reg.h" 52 53 /********************\ 54 * Mac80211 functions * 55 \********************/ 56 57 static void 58 ath5k_tx(struct ieee80211_hw *hw, struct sk_buff *skb) 59 { 60 struct ath5k_hw *ah = hw->priv; 61 u16 qnum = skb_get_queue_mapping(skb); 62 63 if (WARN_ON(qnum >= ah->ah_capabilities.cap_queues.q_tx_num)) { 64 dev_kfree_skb_any(skb); 65 return; 66 } 67 68 ath5k_tx_queue(hw, skb, &ah->txqs[qnum]); 69 } 70 71 72 static int 73 ath5k_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif) 74 { 75 struct ath5k_hw *ah = hw->priv; 76 int ret; 77 struct ath5k_vif *avf = (void *)vif->drv_priv; 78 79 mutex_lock(&ah->lock); 80 81 if ((vif->type == NL80211_IFTYPE_AP || 82 vif->type == NL80211_IFTYPE_ADHOC) 83 && (ah->num_ap_vifs + ah->num_adhoc_vifs) >= ATH_BCBUF) { 84 ret = -ELNRNG; 85 goto end; 86 } 87 88 /* Don't allow other interfaces if one ad-hoc is configured. 89 * TODO: Fix the problems with ad-hoc and multiple other interfaces. 90 * We would need to operate the HW in ad-hoc mode to allow TSF updates 91 * for the IBSS, but this breaks with additional AP or STA interfaces 92 * at the moment. */ 93 if (ah->num_adhoc_vifs || 94 (ah->nvifs && vif->type == NL80211_IFTYPE_ADHOC)) { 95 ATH5K_ERR(ah, "Only one single ad-hoc interface is allowed.\n"); 96 ret = -ELNRNG; 97 goto end; 98 } 99 100 switch (vif->type) { 101 case NL80211_IFTYPE_AP: 102 case NL80211_IFTYPE_STATION: 103 case NL80211_IFTYPE_ADHOC: 104 case NL80211_IFTYPE_MESH_POINT: 105 avf->opmode = vif->type; 106 break; 107 default: 108 ret = -EOPNOTSUPP; 109 goto end; 110 } 111 112 ah->nvifs++; 113 ATH5K_DBG(ah, ATH5K_DEBUG_MODE, "add interface mode %d\n", avf->opmode); 114 115 /* Assign the vap/adhoc to a beacon xmit slot. */ 116 if ((avf->opmode == NL80211_IFTYPE_AP) || 117 (avf->opmode == NL80211_IFTYPE_ADHOC) || 118 (avf->opmode == NL80211_IFTYPE_MESH_POINT)) { 119 int slot; 120 121 WARN_ON(list_empty(&ah->bcbuf)); 122 avf->bbuf = list_first_entry(&ah->bcbuf, struct ath5k_buf, 123 list); 124 list_del(&avf->bbuf->list); 125 126 avf->bslot = 0; 127 for (slot = 0; slot < ATH_BCBUF; slot++) { 128 if (!ah->bslot[slot]) { 129 avf->bslot = slot; 130 break; 131 } 132 } 133 BUG_ON(ah->bslot[avf->bslot] != NULL); 134 ah->bslot[avf->bslot] = vif; 135 if (avf->opmode == NL80211_IFTYPE_AP) 136 ah->num_ap_vifs++; 137 else if (avf->opmode == NL80211_IFTYPE_ADHOC) 138 ah->num_adhoc_vifs++; 139 else if (avf->opmode == NL80211_IFTYPE_MESH_POINT) 140 ah->num_mesh_vifs++; 141 } 142 143 /* Any MAC address is fine, all others are included through the 144 * filter. 145 */ 146 ath5k_hw_set_lladdr(ah, vif->addr); 147 148 ath5k_update_bssid_mask_and_opmode(ah, vif); 149 ret = 0; 150 end: 151 mutex_unlock(&ah->lock); 152 return ret; 153 } 154 155 156 static void 157 ath5k_remove_interface(struct ieee80211_hw *hw, 158 struct ieee80211_vif *vif) 159 { 160 struct ath5k_hw *ah = hw->priv; 161 struct ath5k_vif *avf = (void *)vif->drv_priv; 162 unsigned int i; 163 164 mutex_lock(&ah->lock); 165 ah->nvifs--; 166 167 if (avf->bbuf) { 168 ath5k_txbuf_free_skb(ah, avf->bbuf); 169 list_add_tail(&avf->bbuf->list, &ah->bcbuf); 170 for (i = 0; i < ATH_BCBUF; i++) { 171 if (ah->bslot[i] == vif) { 172 ah->bslot[i] = NULL; 173 break; 174 } 175 } 176 avf->bbuf = NULL; 177 } 178 if (avf->opmode == NL80211_IFTYPE_AP) 179 ah->num_ap_vifs--; 180 else if (avf->opmode == NL80211_IFTYPE_ADHOC) 181 ah->num_adhoc_vifs--; 182 else if (avf->opmode == NL80211_IFTYPE_MESH_POINT) 183 ah->num_mesh_vifs--; 184 185 ath5k_update_bssid_mask_and_opmode(ah, NULL); 186 mutex_unlock(&ah->lock); 187 } 188 189 190 /* 191 * TODO: Phy disable/diversity etc 192 */ 193 static int 194 ath5k_config(struct ieee80211_hw *hw, u32 changed) 195 { 196 struct ath5k_hw *ah = hw->priv; 197 struct ieee80211_conf *conf = &hw->conf; 198 int ret = 0; 199 int i; 200 201 mutex_lock(&ah->lock); 202 203 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { 204 ret = ath5k_chan_set(ah, conf->channel); 205 if (ret < 0) 206 goto unlock; 207 } 208 209 if ((changed & IEEE80211_CONF_CHANGE_POWER) && 210 (ah->power_level != conf->power_level)) { 211 ah->power_level = conf->power_level; 212 213 /* Half dB steps */ 214 ath5k_hw_set_txpower_limit(ah, (conf->power_level * 2)); 215 } 216 217 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) { 218 ah->ah_retry_long = conf->long_frame_max_tx_count; 219 ah->ah_retry_short = conf->short_frame_max_tx_count; 220 221 for (i = 0; i < ah->ah_capabilities.cap_queues.q_tx_num; i++) 222 ath5k_hw_set_tx_retry_limits(ah, i); 223 } 224 225 /* TODO: 226 * 1) Move this on config_interface and handle each case 227 * separately eg. when we have only one STA vif, use 228 * AR5K_ANTMODE_SINGLE_AP 229 * 230 * 2) Allow the user to change antenna mode eg. when only 231 * one antenna is present 232 * 233 * 3) Allow the user to set default/tx antenna when possible 234 * 235 * 4) Default mode should handle 90% of the cases, together 236 * with fixed a/b and single AP modes we should be able to 237 * handle 99%. Sectored modes are extreme cases and i still 238 * haven't found a usage for them. If we decide to support them, 239 * then we must allow the user to set how many tx antennas we 240 * have available 241 */ 242 ath5k_hw_set_antenna_mode(ah, ah->ah_ant_mode); 243 244 unlock: 245 mutex_unlock(&ah->lock); 246 return ret; 247 } 248 249 250 static void 251 ath5k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 252 struct ieee80211_bss_conf *bss_conf, u32 changes) 253 { 254 struct ath5k_vif *avf = (void *)vif->drv_priv; 255 struct ath5k_hw *ah = hw->priv; 256 struct ath_common *common = ath5k_hw_common(ah); 257 unsigned long flags; 258 259 mutex_lock(&ah->lock); 260 261 if (changes & BSS_CHANGED_BSSID) { 262 /* Cache for later use during resets */ 263 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN); 264 common->curaid = 0; 265 ath5k_hw_set_bssid(ah); 266 mmiowb(); 267 } 268 269 if (changes & BSS_CHANGED_BEACON_INT) 270 ah->bintval = bss_conf->beacon_int; 271 272 if (changes & BSS_CHANGED_ERP_SLOT) { 273 int slot_time; 274 275 ah->ah_short_slot = bss_conf->use_short_slot; 276 slot_time = ath5k_hw_get_default_slottime(ah) + 277 3 * ah->ah_coverage_class; 278 ath5k_hw_set_ifs_intervals(ah, slot_time); 279 } 280 281 if (changes & BSS_CHANGED_ASSOC) { 282 avf->assoc = bss_conf->assoc; 283 if (bss_conf->assoc) 284 ah->assoc = bss_conf->assoc; 285 else 286 ah->assoc = ath5k_any_vif_assoc(ah); 287 288 if (ah->opmode == NL80211_IFTYPE_STATION) 289 ath5k_set_beacon_filter(hw, ah->assoc); 290 ath5k_hw_set_ledstate(ah, ah->assoc ? 291 AR5K_LED_ASSOC : AR5K_LED_INIT); 292 if (bss_conf->assoc) { 293 ATH5K_DBG(ah, ATH5K_DEBUG_ANY, 294 "Bss Info ASSOC %d, bssid: %pM\n", 295 bss_conf->aid, common->curbssid); 296 common->curaid = bss_conf->aid; 297 ath5k_hw_set_bssid(ah); 298 /* Once ANI is available you would start it here */ 299 } 300 } 301 302 if (changes & BSS_CHANGED_BEACON) { 303 spin_lock_irqsave(&ah->block, flags); 304 ath5k_beacon_update(hw, vif); 305 spin_unlock_irqrestore(&ah->block, flags); 306 } 307 308 if (changes & BSS_CHANGED_BEACON_ENABLED) 309 ah->enable_beacon = bss_conf->enable_beacon; 310 311 if (changes & (BSS_CHANGED_BEACON | BSS_CHANGED_BEACON_ENABLED | 312 BSS_CHANGED_BEACON_INT)) 313 ath5k_beacon_config(ah); 314 315 mutex_unlock(&ah->lock); 316 } 317 318 319 static u64 320 ath5k_prepare_multicast(struct ieee80211_hw *hw, 321 struct netdev_hw_addr_list *mc_list) 322 { 323 u32 mfilt[2], val; 324 u8 pos; 325 struct netdev_hw_addr *ha; 326 327 mfilt[0] = 0; 328 mfilt[1] = 1; 329 330 netdev_hw_addr_list_for_each(ha, mc_list) { 331 /* calculate XOR of eight 6-bit values */ 332 val = get_unaligned_le32(ha->addr + 0); 333 pos = (val >> 18) ^ (val >> 12) ^ (val >> 6) ^ val; 334 val = get_unaligned_le32(ha->addr + 3); 335 pos ^= (val >> 18) ^ (val >> 12) ^ (val >> 6) ^ val; 336 pos &= 0x3f; 337 mfilt[pos / 32] |= (1 << (pos % 32)); 338 /* XXX: we might be able to just do this instead, 339 * but not sure, needs testing, if we do use this we'd 340 * need to inform below not to reset the mcast */ 341 /* ath5k_hw_set_mcast_filterindex(ah, 342 * ha->addr[5]); */ 343 } 344 345 return ((u64)(mfilt[1]) << 32) | mfilt[0]; 346 } 347 348 349 /* 350 * o always accept unicast, broadcast, and multicast traffic 351 * o multicast traffic for all BSSIDs will be enabled if mac80211 352 * says it should be 353 * o maintain current state of phy ofdm or phy cck error reception. 354 * If the hardware detects any of these type of errors then 355 * ath5k_hw_get_rx_filter() will pass to us the respective 356 * hardware filters to be able to receive these type of frames. 357 * o probe request frames are accepted only when operating in 358 * hostap, adhoc, or monitor modes 359 * o enable promiscuous mode according to the interface state 360 * o accept beacons: 361 * - when operating in adhoc mode so the 802.11 layer creates 362 * node table entries for peers, 363 * - when operating in station mode for collecting rssi data when 364 * the station is otherwise quiet, or 365 * - when scanning 366 */ 367 static void 368 ath5k_configure_filter(struct ieee80211_hw *hw, unsigned int changed_flags, 369 unsigned int *new_flags, u64 multicast) 370 { 371 #define SUPPORTED_FIF_FLAGS \ 372 (FIF_PROMISC_IN_BSS | FIF_ALLMULTI | FIF_FCSFAIL | \ 373 FIF_PLCPFAIL | FIF_CONTROL | FIF_OTHER_BSS | \ 374 FIF_BCN_PRBRESP_PROMISC) 375 376 struct ath5k_hw *ah = hw->priv; 377 u32 mfilt[2], rfilt; 378 struct ath5k_vif_iter_data iter_data; /* to count STA interfaces */ 379 380 mutex_lock(&ah->lock); 381 382 mfilt[0] = multicast; 383 mfilt[1] = multicast >> 32; 384 385 /* Only deal with supported flags */ 386 changed_flags &= SUPPORTED_FIF_FLAGS; 387 *new_flags &= SUPPORTED_FIF_FLAGS; 388 389 /* If HW detects any phy or radar errors, leave those filters on. 390 * Also, always enable Unicast, Broadcasts and Multicast 391 * XXX: move unicast, bssid broadcasts and multicast to mac80211 */ 392 rfilt = (ath5k_hw_get_rx_filter(ah) & (AR5K_RX_FILTER_PHYERR)) | 393 (AR5K_RX_FILTER_UCAST | AR5K_RX_FILTER_BCAST | 394 AR5K_RX_FILTER_MCAST); 395 396 if (changed_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) { 397 if (*new_flags & FIF_PROMISC_IN_BSS) 398 __set_bit(ATH_STAT_PROMISC, ah->status); 399 else 400 __clear_bit(ATH_STAT_PROMISC, ah->status); 401 } 402 403 if (test_bit(ATH_STAT_PROMISC, ah->status)) 404 rfilt |= AR5K_RX_FILTER_PROM; 405 406 /* Note, AR5K_RX_FILTER_MCAST is already enabled */ 407 if (*new_flags & FIF_ALLMULTI) { 408 mfilt[0] = ~0; 409 mfilt[1] = ~0; 410 } 411 412 /* This is the best we can do */ 413 if (*new_flags & (FIF_FCSFAIL | FIF_PLCPFAIL)) 414 rfilt |= AR5K_RX_FILTER_PHYERR; 415 416 /* FIF_BCN_PRBRESP_PROMISC really means to enable beacons 417 * and probes for any BSSID */ 418 if ((*new_flags & FIF_BCN_PRBRESP_PROMISC) || (ah->nvifs > 1)) 419 rfilt |= AR5K_RX_FILTER_BEACON; 420 421 /* FIF_CONTROL doc says that if FIF_PROMISC_IN_BSS is not 422 * set we should only pass on control frames for this 423 * station. This needs testing. I believe right now this 424 * enables *all* control frames, which is OK.. but 425 * but we should see if we can improve on granularity */ 426 if (*new_flags & FIF_CONTROL) 427 rfilt |= AR5K_RX_FILTER_CONTROL; 428 429 /* Additional settings per mode -- this is per ath5k */ 430 431 /* XXX move these to mac80211, and add a beacon IFF flag to mac80211 */ 432 433 switch (ah->opmode) { 434 case NL80211_IFTYPE_MESH_POINT: 435 rfilt |= AR5K_RX_FILTER_CONTROL | 436 AR5K_RX_FILTER_BEACON | 437 AR5K_RX_FILTER_PROBEREQ | 438 AR5K_RX_FILTER_PROM; 439 break; 440 case NL80211_IFTYPE_AP: 441 case NL80211_IFTYPE_ADHOC: 442 rfilt |= AR5K_RX_FILTER_PROBEREQ | 443 AR5K_RX_FILTER_BEACON; 444 break; 445 case NL80211_IFTYPE_STATION: 446 if (ah->assoc) 447 rfilt |= AR5K_RX_FILTER_BEACON; 448 default: 449 break; 450 } 451 452 iter_data.hw_macaddr = NULL; 453 iter_data.n_stas = 0; 454 iter_data.need_set_hw_addr = false; 455 ieee80211_iterate_active_interfaces_atomic(ah->hw, ath5k_vif_iter, 456 &iter_data); 457 458 /* Set up RX Filter */ 459 if (iter_data.n_stas > 1) { 460 /* If you have multiple STA interfaces connected to 461 * different APs, ARPs are not received (most of the time?) 462 * Enabling PROMISC appears to fix that problem. 463 */ 464 rfilt |= AR5K_RX_FILTER_PROM; 465 } 466 467 /* Set filters */ 468 ath5k_hw_set_rx_filter(ah, rfilt); 469 470 /* Set multicast bits */ 471 ath5k_hw_set_mcast_filter(ah, mfilt[0], mfilt[1]); 472 /* Set the cached hw filter flags, this will later actually 473 * be set in HW */ 474 ah->filter_flags = rfilt; 475 476 mutex_unlock(&ah->lock); 477 } 478 479 480 static int 481 ath5k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, 482 struct ieee80211_vif *vif, struct ieee80211_sta *sta, 483 struct ieee80211_key_conf *key) 484 { 485 struct ath5k_hw *ah = hw->priv; 486 struct ath_common *common = ath5k_hw_common(ah); 487 int ret = 0; 488 489 if (ath5k_modparam_nohwcrypt) 490 return -EOPNOTSUPP; 491 492 if (vif->type == NL80211_IFTYPE_ADHOC && 493 (key->cipher == WLAN_CIPHER_SUITE_TKIP || 494 key->cipher == WLAN_CIPHER_SUITE_CCMP) && 495 !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) { 496 /* don't program group keys when using IBSS_RSN */ 497 return -EOPNOTSUPP; 498 } 499 500 switch (key->cipher) { 501 case WLAN_CIPHER_SUITE_WEP40: 502 case WLAN_CIPHER_SUITE_WEP104: 503 case WLAN_CIPHER_SUITE_TKIP: 504 break; 505 case WLAN_CIPHER_SUITE_CCMP: 506 if (common->crypt_caps & ATH_CRYPT_CAP_CIPHER_AESCCM) 507 break; 508 return -EOPNOTSUPP; 509 default: 510 WARN_ON(1); 511 return -EINVAL; 512 } 513 514 mutex_lock(&ah->lock); 515 516 switch (cmd) { 517 case SET_KEY: 518 ret = ath_key_config(common, vif, sta, key); 519 if (ret >= 0) { 520 key->hw_key_idx = ret; 521 /* push IV and Michael MIC generation to stack */ 522 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; 523 if (key->cipher == WLAN_CIPHER_SUITE_TKIP) 524 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; 525 if (key->cipher == WLAN_CIPHER_SUITE_CCMP) 526 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT; 527 ret = 0; 528 } 529 break; 530 case DISABLE_KEY: 531 ath_key_delete(common, key); 532 break; 533 default: 534 ret = -EINVAL; 535 } 536 537 mmiowb(); 538 mutex_unlock(&ah->lock); 539 return ret; 540 } 541 542 543 static void 544 ath5k_sw_scan_start(struct ieee80211_hw *hw) 545 { 546 struct ath5k_hw *ah = hw->priv; 547 if (!ah->assoc) 548 ath5k_hw_set_ledstate(ah, AR5K_LED_SCAN); 549 } 550 551 552 static void 553 ath5k_sw_scan_complete(struct ieee80211_hw *hw) 554 { 555 struct ath5k_hw *ah = hw->priv; 556 ath5k_hw_set_ledstate(ah, ah->assoc ? 557 AR5K_LED_ASSOC : AR5K_LED_INIT); 558 } 559 560 561 static int 562 ath5k_get_stats(struct ieee80211_hw *hw, 563 struct ieee80211_low_level_stats *stats) 564 { 565 struct ath5k_hw *ah = hw->priv; 566 567 /* Force update */ 568 ath5k_hw_update_mib_counters(ah); 569 570 stats->dot11ACKFailureCount = ah->stats.ack_fail; 571 stats->dot11RTSFailureCount = ah->stats.rts_fail; 572 stats->dot11RTSSuccessCount = ah->stats.rts_ok; 573 stats->dot11FCSErrorCount = ah->stats.fcs_error; 574 575 return 0; 576 } 577 578 579 static int 580 ath5k_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u16 queue, 581 const struct ieee80211_tx_queue_params *params) 582 { 583 struct ath5k_hw *ah = hw->priv; 584 struct ath5k_txq_info qi; 585 int ret = 0; 586 587 if (queue >= ah->ah_capabilities.cap_queues.q_tx_num) 588 return 0; 589 590 mutex_lock(&ah->lock); 591 592 ath5k_hw_get_tx_queueprops(ah, queue, &qi); 593 594 qi.tqi_aifs = params->aifs; 595 qi.tqi_cw_min = params->cw_min; 596 qi.tqi_cw_max = params->cw_max; 597 qi.tqi_burst_time = params->txop; 598 599 ATH5K_DBG(ah, ATH5K_DEBUG_ANY, 600 "Configure tx [queue %d], " 601 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n", 602 queue, params->aifs, params->cw_min, 603 params->cw_max, params->txop); 604 605 if (ath5k_hw_set_tx_queueprops(ah, queue, &qi)) { 606 ATH5K_ERR(ah, 607 "Unable to update hardware queue %u!\n", queue); 608 ret = -EIO; 609 } else 610 ath5k_hw_reset_tx_queue(ah, queue); 611 612 mutex_unlock(&ah->lock); 613 614 return ret; 615 } 616 617 618 static u64 619 ath5k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif) 620 { 621 struct ath5k_hw *ah = hw->priv; 622 623 return ath5k_hw_get_tsf64(ah); 624 } 625 626 627 static void 628 ath5k_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u64 tsf) 629 { 630 struct ath5k_hw *ah = hw->priv; 631 632 ath5k_hw_set_tsf64(ah, tsf); 633 } 634 635 636 static void 637 ath5k_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif) 638 { 639 struct ath5k_hw *ah = hw->priv; 640 641 /* 642 * in IBSS mode we need to update the beacon timers too. 643 * this will also reset the TSF if we call it with 0 644 */ 645 if (ah->opmode == NL80211_IFTYPE_ADHOC) 646 ath5k_beacon_update_timers(ah, 0); 647 else 648 ath5k_hw_reset_tsf(ah); 649 } 650 651 652 static int 653 ath5k_get_survey(struct ieee80211_hw *hw, int idx, struct survey_info *survey) 654 { 655 struct ath5k_hw *ah = hw->priv; 656 struct ieee80211_conf *conf = &hw->conf; 657 struct ath_common *common = ath5k_hw_common(ah); 658 struct ath_cycle_counters *cc = &common->cc_survey; 659 unsigned int div = common->clockrate * 1000; 660 661 if (idx != 0) 662 return -ENOENT; 663 664 spin_lock_bh(&common->cc_lock); 665 ath_hw_cycle_counters_update(common); 666 if (cc->cycles > 0) { 667 ah->survey.channel_time += cc->cycles / div; 668 ah->survey.channel_time_busy += cc->rx_busy / div; 669 ah->survey.channel_time_rx += cc->rx_frame / div; 670 ah->survey.channel_time_tx += cc->tx_frame / div; 671 } 672 memset(cc, 0, sizeof(*cc)); 673 spin_unlock_bh(&common->cc_lock); 674 675 memcpy(survey, &ah->survey, sizeof(*survey)); 676 677 survey->channel = conf->channel; 678 survey->noise = ah->ah_noise_floor; 679 survey->filled = SURVEY_INFO_NOISE_DBM | 680 SURVEY_INFO_CHANNEL_TIME | 681 SURVEY_INFO_CHANNEL_TIME_BUSY | 682 SURVEY_INFO_CHANNEL_TIME_RX | 683 SURVEY_INFO_CHANNEL_TIME_TX; 684 685 return 0; 686 } 687 688 689 /** 690 * ath5k_set_coverage_class - Set IEEE 802.11 coverage class 691 * 692 * @hw: struct ieee80211_hw pointer 693 * @coverage_class: IEEE 802.11 coverage class number 694 * 695 * Mac80211 callback. Sets slot time, ACK timeout and CTS timeout for given 696 * coverage class. The values are persistent, they are restored after device 697 * reset. 698 */ 699 static void 700 ath5k_set_coverage_class(struct ieee80211_hw *hw, u8 coverage_class) 701 { 702 struct ath5k_hw *ah = hw->priv; 703 704 mutex_lock(&ah->lock); 705 ath5k_hw_set_coverage_class(ah, coverage_class); 706 mutex_unlock(&ah->lock); 707 } 708 709 710 static int 711 ath5k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant) 712 { 713 struct ath5k_hw *ah = hw->priv; 714 715 if (tx_ant == 1 && rx_ant == 1) 716 ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_FIXED_A); 717 else if (tx_ant == 2 && rx_ant == 2) 718 ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_FIXED_B); 719 else if ((tx_ant & 3) == 3 && (rx_ant & 3) == 3) 720 ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_DEFAULT); 721 else 722 return -EINVAL; 723 return 0; 724 } 725 726 727 static int 728 ath5k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant) 729 { 730 struct ath5k_hw *ah = hw->priv; 731 732 switch (ah->ah_ant_mode) { 733 case AR5K_ANTMODE_FIXED_A: 734 *tx_ant = 1; *rx_ant = 1; break; 735 case AR5K_ANTMODE_FIXED_B: 736 *tx_ant = 2; *rx_ant = 2; break; 737 case AR5K_ANTMODE_DEFAULT: 738 *tx_ant = 3; *rx_ant = 3; break; 739 } 740 return 0; 741 } 742 743 744 static void ath5k_get_ringparam(struct ieee80211_hw *hw, 745 u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max) 746 { 747 struct ath5k_hw *ah = hw->priv; 748 749 *tx = ah->txqs[AR5K_TX_QUEUE_ID_DATA_MIN].txq_max; 750 751 *tx_max = ATH5K_TXQ_LEN_MAX; 752 *rx = *rx_max = ATH_RXBUF; 753 } 754 755 756 static int ath5k_set_ringparam(struct ieee80211_hw *hw, u32 tx, u32 rx) 757 { 758 struct ath5k_hw *ah = hw->priv; 759 u16 qnum; 760 761 /* only support setting tx ring size for now */ 762 if (rx != ATH_RXBUF) 763 return -EINVAL; 764 765 /* restrict tx ring size min/max */ 766 if (!tx || tx > ATH5K_TXQ_LEN_MAX) 767 return -EINVAL; 768 769 for (qnum = 0; qnum < ARRAY_SIZE(ah->txqs); qnum++) { 770 if (!ah->txqs[qnum].setup) 771 continue; 772 if (ah->txqs[qnum].qnum < AR5K_TX_QUEUE_ID_DATA_MIN || 773 ah->txqs[qnum].qnum > AR5K_TX_QUEUE_ID_DATA_MAX) 774 continue; 775 776 ah->txqs[qnum].txq_max = tx; 777 if (ah->txqs[qnum].txq_len >= ah->txqs[qnum].txq_max) 778 ieee80211_stop_queue(hw, ah->txqs[qnum].qnum); 779 } 780 781 return 0; 782 } 783 784 785 const struct ieee80211_ops ath5k_hw_ops = { 786 .tx = ath5k_tx, 787 .start = ath5k_start, 788 .stop = ath5k_stop, 789 .add_interface = ath5k_add_interface, 790 /* .change_interface = not implemented */ 791 .remove_interface = ath5k_remove_interface, 792 .config = ath5k_config, 793 .bss_info_changed = ath5k_bss_info_changed, 794 .prepare_multicast = ath5k_prepare_multicast, 795 .configure_filter = ath5k_configure_filter, 796 /* .set_tim = not implemented */ 797 .set_key = ath5k_set_key, 798 /* .update_tkip_key = not implemented */ 799 /* .hw_scan = not implemented */ 800 .sw_scan_start = ath5k_sw_scan_start, 801 .sw_scan_complete = ath5k_sw_scan_complete, 802 .get_stats = ath5k_get_stats, 803 /* .get_tkip_seq = not implemented */ 804 /* .set_frag_threshold = not implemented */ 805 /* .set_rts_threshold = not implemented */ 806 /* .sta_add = not implemented */ 807 /* .sta_remove = not implemented */ 808 /* .sta_notify = not implemented */ 809 .conf_tx = ath5k_conf_tx, 810 .get_tsf = ath5k_get_tsf, 811 .set_tsf = ath5k_set_tsf, 812 .reset_tsf = ath5k_reset_tsf, 813 /* .tx_last_beacon = not implemented */ 814 /* .ampdu_action = not needed */ 815 .get_survey = ath5k_get_survey, 816 .set_coverage_class = ath5k_set_coverage_class, 817 /* .rfkill_poll = not implemented */ 818 /* .flush = not implemented */ 819 /* .channel_switch = not implemented */ 820 /* .napi_poll = not implemented */ 821 .set_antenna = ath5k_set_antenna, 822 .get_antenna = ath5k_get_antenna, 823 .set_ringparam = ath5k_set_ringparam, 824 .get_ringparam = ath5k_get_ringparam, 825 }; 826