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