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 | |
Joe Perches | 516304b | 2012-03-18 17:30:52 -0700 | [diff] [blame] | 44 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 45 | |
Pavel Roskin | 931be26 | 2011-07-26 22:26:59 -0400 | [diff] [blame] | 46 | #include <net/mac80211.h> |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 47 | #include <asm/unaligned.h> |
| 48 | |
Pavel Roskin | 931be26 | 2011-07-26 22:26:59 -0400 | [diff] [blame] | 49 | #include "ath5k.h" |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 50 | #include "base.h" |
| 51 | #include "reg.h" |
| 52 | |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 53 | /********************\ |
| 54 | * Mac80211 functions * |
| 55 | \********************/ |
| 56 | |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 57 | static void |
Thomas Huehn | 36323f8 | 2012-07-23 21:33:42 +0200 | [diff] [blame] | 58 | ath5k_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control, |
| 59 | struct sk_buff *skb) |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 60 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 61 | struct ath5k_hw *ah = hw->priv; |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 62 | u16 qnum = skb_get_queue_mapping(skb); |
| 63 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 64 | if (WARN_ON(qnum >= ah->ah_capabilities.cap_queues.q_tx_num)) { |
Felix Fietkau | 596ab5e | 2012-12-10 16:40:41 +0100 | [diff] [blame] | 65 | ieee80211_free_txskb(hw, skb); |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 66 | return; |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 67 | } |
| 68 | |
Thomas Huehn | 0967e01 | 2013-06-11 15:10:31 +0200 | [diff] [blame] | 69 | ath5k_tx_queue(hw, skb, &ah->txqs[qnum], control); |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | |
| 73 | static int |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 74 | ath5k_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif) |
| 75 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 76 | struct ath5k_hw *ah = hw->priv; |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 77 | int ret; |
| 78 | struct ath5k_vif *avf = (void *)vif->drv_priv; |
| 79 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 80 | mutex_lock(&ah->lock); |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 81 | |
| 82 | if ((vif->type == NL80211_IFTYPE_AP || |
| 83 | vif->type == NL80211_IFTYPE_ADHOC) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 84 | && (ah->num_ap_vifs + ah->num_adhoc_vifs) >= ATH_BCBUF) { |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 85 | ret = -ELNRNG; |
| 86 | goto end; |
| 87 | } |
| 88 | |
| 89 | /* Don't allow other interfaces if one ad-hoc is configured. |
| 90 | * TODO: Fix the problems with ad-hoc and multiple other interfaces. |
| 91 | * We would need to operate the HW in ad-hoc mode to allow TSF updates |
| 92 | * for the IBSS, but this breaks with additional AP or STA interfaces |
| 93 | * at the moment. */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 94 | if (ah->num_adhoc_vifs || |
| 95 | (ah->nvifs && vif->type == NL80211_IFTYPE_ADHOC)) { |
| 96 | ATH5K_ERR(ah, "Only one single ad-hoc interface is allowed.\n"); |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 97 | ret = -ELNRNG; |
| 98 | goto end; |
| 99 | } |
| 100 | |
| 101 | switch (vif->type) { |
| 102 | case NL80211_IFTYPE_AP: |
| 103 | case NL80211_IFTYPE_STATION: |
| 104 | case NL80211_IFTYPE_ADHOC: |
| 105 | case NL80211_IFTYPE_MESH_POINT: |
| 106 | avf->opmode = vif->type; |
| 107 | break; |
| 108 | default: |
| 109 | ret = -EOPNOTSUPP; |
| 110 | goto end; |
| 111 | } |
| 112 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 113 | ah->nvifs++; |
| 114 | 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] | 115 | |
| 116 | /* Assign the vap/adhoc to a beacon xmit slot. */ |
| 117 | if ((avf->opmode == NL80211_IFTYPE_AP) || |
| 118 | (avf->opmode == NL80211_IFTYPE_ADHOC) || |
| 119 | (avf->opmode == NL80211_IFTYPE_MESH_POINT)) { |
| 120 | int slot; |
| 121 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 122 | WARN_ON(list_empty(&ah->bcbuf)); |
| 123 | avf->bbuf = list_first_entry(&ah->bcbuf, struct ath5k_buf, |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 124 | list); |
| 125 | list_del(&avf->bbuf->list); |
| 126 | |
| 127 | avf->bslot = 0; |
| 128 | for (slot = 0; slot < ATH_BCBUF; slot++) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 129 | if (!ah->bslot[slot]) { |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 130 | avf->bslot = slot; |
| 131 | break; |
| 132 | } |
| 133 | } |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 134 | BUG_ON(ah->bslot[avf->bslot] != NULL); |
| 135 | ah->bslot[avf->bslot] = vif; |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 136 | if (avf->opmode == NL80211_IFTYPE_AP) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 137 | ah->num_ap_vifs++; |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 138 | else if (avf->opmode == NL80211_IFTYPE_ADHOC) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 139 | ah->num_adhoc_vifs++; |
Chun-Yeow Yeoh | da473b6 | 2012-03-03 09:48:56 +0800 | [diff] [blame] | 140 | else if (avf->opmode == NL80211_IFTYPE_MESH_POINT) |
| 141 | ah->num_mesh_vifs++; |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | /* Any MAC address is fine, all others are included through the |
| 145 | * filter. |
| 146 | */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 147 | ath5k_hw_set_lladdr(ah, vif->addr); |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 148 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 149 | ath5k_update_bssid_mask_and_opmode(ah, vif); |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 150 | ret = 0; |
| 151 | end: |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 152 | mutex_unlock(&ah->lock); |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 153 | return ret; |
| 154 | } |
| 155 | |
| 156 | |
| 157 | static void |
| 158 | ath5k_remove_interface(struct ieee80211_hw *hw, |
| 159 | struct ieee80211_vif *vif) |
| 160 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 161 | struct ath5k_hw *ah = hw->priv; |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 162 | struct ath5k_vif *avf = (void *)vif->drv_priv; |
| 163 | unsigned int i; |
| 164 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 165 | mutex_lock(&ah->lock); |
| 166 | ah->nvifs--; |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 167 | |
| 168 | if (avf->bbuf) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 169 | ath5k_txbuf_free_skb(ah, avf->bbuf); |
| 170 | list_add_tail(&avf->bbuf->list, &ah->bcbuf); |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 171 | for (i = 0; i < ATH_BCBUF; i++) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 172 | if (ah->bslot[i] == vif) { |
| 173 | ah->bslot[i] = NULL; |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 174 | break; |
| 175 | } |
| 176 | } |
| 177 | avf->bbuf = NULL; |
| 178 | } |
| 179 | if (avf->opmode == NL80211_IFTYPE_AP) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 180 | ah->num_ap_vifs--; |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 181 | else if (avf->opmode == NL80211_IFTYPE_ADHOC) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 182 | ah->num_adhoc_vifs--; |
Chun-Yeow Yeoh | da473b6 | 2012-03-03 09:48:56 +0800 | [diff] [blame] | 183 | else if (avf->opmode == NL80211_IFTYPE_MESH_POINT) |
| 184 | ah->num_mesh_vifs--; |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 185 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 186 | ath5k_update_bssid_mask_and_opmode(ah, NULL); |
| 187 | mutex_unlock(&ah->lock); |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | |
| 191 | /* |
| 192 | * TODO: Phy disable/diversity etc |
| 193 | */ |
| 194 | static int |
| 195 | ath5k_config(struct ieee80211_hw *hw, u32 changed) |
| 196 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 197 | struct ath5k_hw *ah = hw->priv; |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 198 | struct ieee80211_conf *conf = &hw->conf; |
| 199 | int ret = 0; |
Bruno Randolf | 76a9f6f | 2011-01-28 16:52:11 +0900 | [diff] [blame] | 200 | int i; |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 201 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 202 | mutex_lock(&ah->lock); |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 203 | |
| 204 | if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { |
Simon Wunderlich | 4d70f2f | 2013-08-14 08:01:37 +0200 | [diff] [blame] | 205 | ret = ath5k_chan_set(ah, &conf->chandef); |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 206 | if (ret < 0) |
| 207 | goto unlock; |
| 208 | } |
| 209 | |
| 210 | if ((changed & IEEE80211_CONF_CHANGE_POWER) && |
Nick Kossifidis | 987af54 | 2012-08-05 22:35:36 +0300 | [diff] [blame] | 211 | (ah->ah_txpower.txp_requested != conf->power_level)) { |
| 212 | ah->ah_txpower.txp_requested = conf->power_level; |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 213 | |
| 214 | /* Half dB steps */ |
| 215 | ath5k_hw_set_txpower_limit(ah, (conf->power_level * 2)); |
| 216 | } |
| 217 | |
Bruno Randolf | 76a9f6f | 2011-01-28 16:52:11 +0900 | [diff] [blame] | 218 | if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) { |
| 219 | ah->ah_retry_long = conf->long_frame_max_tx_count; |
| 220 | ah->ah_retry_short = conf->short_frame_max_tx_count; |
| 221 | |
| 222 | for (i = 0; i < ah->ah_capabilities.cap_queues.q_tx_num; i++) |
| 223 | ath5k_hw_set_tx_retry_limits(ah, i); |
| 224 | } |
| 225 | |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 226 | /* TODO: |
| 227 | * 1) Move this on config_interface and handle each case |
| 228 | * separately eg. when we have only one STA vif, use |
| 229 | * AR5K_ANTMODE_SINGLE_AP |
| 230 | * |
| 231 | * 2) Allow the user to change antenna mode eg. when only |
| 232 | * one antenna is present |
| 233 | * |
| 234 | * 3) Allow the user to set default/tx antenna when possible |
| 235 | * |
| 236 | * 4) Default mode should handle 90% of the cases, together |
| 237 | * with fixed a/b and single AP modes we should be able to |
| 238 | * handle 99%. Sectored modes are extreme cases and i still |
| 239 | * haven't found a usage for them. If we decide to support them, |
| 240 | * then we must allow the user to set how many tx antennas we |
| 241 | * have available |
| 242 | */ |
| 243 | ath5k_hw_set_antenna_mode(ah, ah->ah_ant_mode); |
| 244 | |
| 245 | unlock: |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 246 | mutex_unlock(&ah->lock); |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 247 | return ret; |
| 248 | } |
| 249 | |
| 250 | |
| 251 | static void |
| 252 | ath5k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 253 | struct ieee80211_bss_conf *bss_conf, u32 changes) |
| 254 | { |
| 255 | struct ath5k_vif *avf = (void *)vif->drv_priv; |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 256 | struct ath5k_hw *ah = hw->priv; |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 257 | struct ath_common *common = ath5k_hw_common(ah); |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 258 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 259 | mutex_lock(&ah->lock); |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 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) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 270 | ah->bintval = bss_conf->beacon_int; |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 271 | |
Felix Fietkau | b1ad1b6 | 2011-04-09 23:10:21 +0200 | [diff] [blame] | 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 | |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 281 | if (changes & BSS_CHANGED_ASSOC) { |
| 282 | avf->assoc = bss_conf->assoc; |
| 283 | if (bss_conf->assoc) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 284 | ah->assoc = bss_conf->assoc; |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 285 | else |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 286 | ah->assoc = ath5k_any_vif_assoc(ah); |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 287 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 288 | if (ah->opmode == NL80211_IFTYPE_STATION) |
| 289 | ath5k_set_beacon_filter(hw, ah->assoc); |
| 290 | ath5k_hw_set_ledstate(ah, ah->assoc ? |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 291 | AR5K_LED_ASSOC : AR5K_LED_INIT); |
| 292 | if (bss_conf->assoc) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 293 | ATH5K_DBG(ah, ATH5K_DEBUG_ANY, |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 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) { |
Bob Copeland | 7dd6753 | 2012-08-12 21:18:33 -0400 | [diff] [blame] | 303 | spin_lock_bh(&ah->block); |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 304 | ath5k_beacon_update(hw, vif); |
Bob Copeland | 7dd6753 | 2012-08-12 21:18:33 -0400 | [diff] [blame] | 305 | spin_unlock_bh(&ah->block); |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | if (changes & BSS_CHANGED_BEACON_ENABLED) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 309 | ah->enable_beacon = bss_conf->enable_beacon; |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 310 | |
| 311 | if (changes & (BSS_CHANGED_BEACON | BSS_CHANGED_BEACON_ENABLED | |
| 312 | BSS_CHANGED_BEACON_INT)) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 313 | ath5k_beacon_config(ah); |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 314 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 315 | mutex_unlock(&ah->lock); |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 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; |
Bob Copeland | f287cbd | 2013-07-11 09:19:13 -0400 | [diff] [blame] | 328 | mfilt[1] = 0; |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 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 |
Pavel Roskin | 6a2a0e7 | 2011-07-09 00:17:51 -0400 | [diff] [blame] | 340 | * need to inform below not to reset the mcast */ |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 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 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 376 | struct ath5k_hw *ah = hw->priv; |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 377 | u32 mfilt[2], rfilt; |
Ben Greear | e4b0b32 | 2011-03-03 14:39:05 -0800 | [diff] [blame] | 378 | struct ath5k_vif_iter_data iter_data; /* to count STA interfaces */ |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 379 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 380 | mutex_lock(&ah->lock); |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 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) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 398 | __set_bit(ATH_STAT_PROMISC, ah->status); |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 399 | else |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 400 | __clear_bit(ATH_STAT_PROMISC, ah->status); |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 401 | } |
| 402 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 403 | if (test_bit(ATH_STAT_PROMISC, ah->status)) |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 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 */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 418 | if ((*new_flags & FIF_BCN_PRBRESP_PROMISC) || (ah->nvifs > 1)) |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 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 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 433 | switch (ah->opmode) { |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 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: |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 446 | if (ah->assoc) |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 447 | rfilt |= AR5K_RX_FILTER_BEACON; |
| 448 | default: |
| 449 | break; |
| 450 | } |
| 451 | |
Ben Greear | e4b0b32 | 2011-03-03 14:39:05 -0800 | [diff] [blame] | 452 | iter_data.hw_macaddr = NULL; |
| 453 | iter_data.n_stas = 0; |
| 454 | iter_data.need_set_hw_addr = false; |
Johannes Berg | 8b2c982 | 2012-11-06 20:23:30 +0100 | [diff] [blame] | 455 | ieee80211_iterate_active_interfaces_atomic( |
| 456 | ah->hw, IEEE80211_IFACE_ITER_RESUME_ALL, |
| 457 | ath5k_vif_iter, &iter_data); |
Ben Greear | e4b0b32 | 2011-03-03 14:39:05 -0800 | [diff] [blame] | 458 | |
| 459 | /* Set up RX Filter */ |
| 460 | if (iter_data.n_stas > 1) { |
| 461 | /* If you have multiple STA interfaces connected to |
| 462 | * different APs, ARPs are not received (most of the time?) |
Pavel Roskin | 6a2a0e7 | 2011-07-09 00:17:51 -0400 | [diff] [blame] | 463 | * Enabling PROMISC appears to fix that problem. |
Ben Greear | e4b0b32 | 2011-03-03 14:39:05 -0800 | [diff] [blame] | 464 | */ |
| 465 | rfilt |= AR5K_RX_FILTER_PROM; |
| 466 | } |
| 467 | |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 468 | /* Set filters */ |
| 469 | ath5k_hw_set_rx_filter(ah, rfilt); |
| 470 | |
| 471 | /* Set multicast bits */ |
| 472 | ath5k_hw_set_mcast_filter(ah, mfilt[0], mfilt[1]); |
| 473 | /* Set the cached hw filter flags, this will later actually |
| 474 | * be set in HW */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 475 | ah->filter_flags = rfilt; |
Mathy Vanhoef | 4188135 | 2014-06-13 23:40:22 +0200 | [diff] [blame] | 476 | /* Store current FIF filter flags */ |
| 477 | ah->fif_filter_flags = *new_flags; |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 478 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 479 | mutex_unlock(&ah->lock); |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | |
| 483 | static int |
| 484 | ath5k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, |
| 485 | struct ieee80211_vif *vif, struct ieee80211_sta *sta, |
| 486 | struct ieee80211_key_conf *key) |
| 487 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 488 | struct ath5k_hw *ah = hw->priv; |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 489 | struct ath_common *common = ath5k_hw_common(ah); |
| 490 | int ret = 0; |
| 491 | |
John W. Linville | 18cb6e3 | 2011-01-05 09:39:59 -0500 | [diff] [blame] | 492 | if (ath5k_modparam_nohwcrypt) |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 493 | return -EOPNOTSUPP; |
| 494 | |
Chun-Yeow Yeoh | 90e6274 | 2012-09-14 18:26:11 +0800 | [diff] [blame] | 495 | if (key->flags & IEEE80211_KEY_FLAG_RX_MGMT) |
| 496 | return -EOPNOTSUPP; |
| 497 | |
Antonio Quartulli | f997257 | 2012-01-14 11:42:43 +0100 | [diff] [blame] | 498 | if (vif->type == NL80211_IFTYPE_ADHOC && |
| 499 | (key->cipher == WLAN_CIPHER_SUITE_TKIP || |
| 500 | key->cipher == WLAN_CIPHER_SUITE_CCMP) && |
| 501 | !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) { |
| 502 | /* don't program group keys when using IBSS_RSN */ |
| 503 | return -EOPNOTSUPP; |
| 504 | } |
| 505 | |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 506 | switch (key->cipher) { |
| 507 | case WLAN_CIPHER_SUITE_WEP40: |
| 508 | case WLAN_CIPHER_SUITE_WEP104: |
| 509 | case WLAN_CIPHER_SUITE_TKIP: |
| 510 | break; |
| 511 | case WLAN_CIPHER_SUITE_CCMP: |
| 512 | if (common->crypt_caps & ATH_CRYPT_CAP_CIPHER_AESCCM) |
| 513 | break; |
| 514 | return -EOPNOTSUPP; |
| 515 | default: |
| 516 | WARN_ON(1); |
| 517 | return -EINVAL; |
| 518 | } |
| 519 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 520 | mutex_lock(&ah->lock); |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 521 | |
| 522 | switch (cmd) { |
| 523 | case SET_KEY: |
| 524 | ret = ath_key_config(common, vif, sta, key); |
| 525 | if (ret >= 0) { |
| 526 | key->hw_key_idx = ret; |
| 527 | /* push IV and Michael MIC generation to stack */ |
| 528 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 529 | if (key->cipher == WLAN_CIPHER_SUITE_TKIP) |
| 530 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; |
| 531 | if (key->cipher == WLAN_CIPHER_SUITE_CCMP) |
Johannes Berg | e548c49 | 2012-09-04 17:08:23 +0200 | [diff] [blame] | 532 | key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX; |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 533 | ret = 0; |
| 534 | } |
| 535 | break; |
| 536 | case DISABLE_KEY: |
| 537 | ath_key_delete(common, key); |
| 538 | break; |
| 539 | default: |
| 540 | ret = -EINVAL; |
| 541 | } |
| 542 | |
| 543 | mmiowb(); |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 544 | mutex_unlock(&ah->lock); |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 545 | return ret; |
| 546 | } |
| 547 | |
| 548 | |
| 549 | static void |
Johannes Berg | a344d67 | 2014-06-12 22:24:31 +0200 | [diff] [blame] | 550 | ath5k_sw_scan_start(struct ieee80211_hw *hw, |
| 551 | struct ieee80211_vif *vif, |
| 552 | const u8 *mac_addr) |
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 | struct ath5k_hw *ah = hw->priv; |
| 555 | if (!ah->assoc) |
| 556 | ath5k_hw_set_ledstate(ah, AR5K_LED_SCAN); |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | |
| 560 | static void |
Johannes Berg | a344d67 | 2014-06-12 22:24:31 +0200 | [diff] [blame] | 561 | ath5k_sw_scan_complete(struct ieee80211_hw *hw, struct ieee80211_vif *vif) |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 562 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 563 | struct ath5k_hw *ah = hw->priv; |
| 564 | ath5k_hw_set_ledstate(ah, ah->assoc ? |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 565 | AR5K_LED_ASSOC : AR5K_LED_INIT); |
| 566 | } |
| 567 | |
| 568 | |
| 569 | static int |
| 570 | ath5k_get_stats(struct ieee80211_hw *hw, |
| 571 | struct ieee80211_low_level_stats *stats) |
| 572 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 573 | struct ath5k_hw *ah = hw->priv; |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 574 | |
| 575 | /* Force update */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 576 | ath5k_hw_update_mib_counters(ah); |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 577 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 578 | stats->dot11ACKFailureCount = ah->stats.ack_fail; |
| 579 | stats->dot11RTSFailureCount = ah->stats.rts_fail; |
| 580 | stats->dot11RTSSuccessCount = ah->stats.rts_ok; |
| 581 | stats->dot11FCSErrorCount = ah->stats.fcs_error; |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 582 | |
| 583 | return 0; |
| 584 | } |
| 585 | |
| 586 | |
| 587 | static int |
Eliad Peller | 8a3a3c8 | 2011-10-02 10:15:52 +0200 | [diff] [blame] | 588 | ath5k_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u16 queue, |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 589 | const struct ieee80211_tx_queue_params *params) |
| 590 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 591 | struct ath5k_hw *ah = hw->priv; |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 592 | struct ath5k_txq_info qi; |
| 593 | int ret = 0; |
| 594 | |
| 595 | if (queue >= ah->ah_capabilities.cap_queues.q_tx_num) |
| 596 | return 0; |
| 597 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 598 | mutex_lock(&ah->lock); |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 599 | |
| 600 | ath5k_hw_get_tx_queueprops(ah, queue, &qi); |
| 601 | |
| 602 | qi.tqi_aifs = params->aifs; |
| 603 | qi.tqi_cw_min = params->cw_min; |
| 604 | qi.tqi_cw_max = params->cw_max; |
Felix Fietkau | 0f245ed | 2012-07-16 19:49:07 +0200 | [diff] [blame] | 605 | qi.tqi_burst_time = params->txop * 32; |
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 | ATH5K_DBG(ah, ATH5K_DEBUG_ANY, |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 608 | "Configure tx [queue %d], " |
| 609 | "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n", |
| 610 | queue, params->aifs, params->cw_min, |
| 611 | params->cw_max, params->txop); |
| 612 | |
| 613 | if (ath5k_hw_set_tx_queueprops(ah, queue, &qi)) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 614 | ATH5K_ERR(ah, |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 615 | "Unable to update hardware queue %u!\n", queue); |
| 616 | ret = -EIO; |
| 617 | } else |
| 618 | ath5k_hw_reset_tx_queue(ah, queue); |
| 619 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 620 | mutex_unlock(&ah->lock); |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 621 | |
| 622 | return ret; |
| 623 | } |
| 624 | |
| 625 | |
| 626 | static u64 |
Eliad Peller | 37a41b4 | 2011-09-21 14:06:11 +0300 | [diff] [blame] | 627 | ath5k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif) |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 628 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 629 | struct ath5k_hw *ah = hw->priv; |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 630 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 631 | return ath5k_hw_get_tsf64(ah); |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | |
| 635 | static void |
Eliad Peller | 37a41b4 | 2011-09-21 14:06:11 +0300 | [diff] [blame] | 636 | ath5k_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u64 tsf) |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 637 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 638 | struct ath5k_hw *ah = hw->priv; |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 639 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 640 | ath5k_hw_set_tsf64(ah, tsf); |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | |
| 644 | static void |
Eliad Peller | 37a41b4 | 2011-09-21 14:06:11 +0300 | [diff] [blame] | 645 | ath5k_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif) |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 646 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 647 | struct ath5k_hw *ah = hw->priv; |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 648 | |
| 649 | /* |
| 650 | * in IBSS mode we need to update the beacon timers too. |
| 651 | * this will also reset the TSF if we call it with 0 |
| 652 | */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 653 | if (ah->opmode == NL80211_IFTYPE_ADHOC) |
| 654 | ath5k_beacon_update_timers(ah, 0); |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 655 | else |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 656 | ath5k_hw_reset_tsf(ah); |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | |
| 660 | static int |
| 661 | ath5k_get_survey(struct ieee80211_hw *hw, int idx, struct survey_info *survey) |
| 662 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 663 | struct ath5k_hw *ah = hw->priv; |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 664 | struct ieee80211_conf *conf = &hw->conf; |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 665 | struct ath_common *common = ath5k_hw_common(ah); |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 666 | struct ath_cycle_counters *cc = &common->cc_survey; |
| 667 | unsigned int div = common->clockrate * 1000; |
| 668 | |
| 669 | if (idx != 0) |
| 670 | return -ENOENT; |
| 671 | |
| 672 | spin_lock_bh(&common->cc_lock); |
| 673 | ath_hw_cycle_counters_update(common); |
| 674 | if (cc->cycles > 0) { |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 675 | ah->survey.time += cc->cycles / div; |
| 676 | ah->survey.time_busy += cc->rx_busy / div; |
| 677 | ah->survey.time_rx += cc->rx_frame / div; |
| 678 | ah->survey.time_tx += cc->tx_frame / div; |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 679 | } |
| 680 | memset(cc, 0, sizeof(*cc)); |
| 681 | spin_unlock_bh(&common->cc_lock); |
| 682 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 683 | memcpy(survey, &ah->survey, sizeof(*survey)); |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 684 | |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 685 | survey->channel = conf->chandef.chan; |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 686 | survey->noise = ah->ah_noise_floor; |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 687 | survey->filled = SURVEY_INFO_NOISE_DBM | |
Felix Fietkau | ef1b414 | 2014-02-22 14:55:57 +0100 | [diff] [blame] | 688 | SURVEY_INFO_IN_USE | |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 689 | SURVEY_INFO_TIME | |
| 690 | SURVEY_INFO_TIME_BUSY | |
| 691 | SURVEY_INFO_TIME_RX | |
| 692 | SURVEY_INFO_TIME_TX; |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 693 | |
| 694 | return 0; |
| 695 | } |
| 696 | |
| 697 | |
| 698 | /** |
| 699 | * ath5k_set_coverage_class - Set IEEE 802.11 coverage class |
| 700 | * |
| 701 | * @hw: struct ieee80211_hw pointer |
| 702 | * @coverage_class: IEEE 802.11 coverage class number |
| 703 | * |
| 704 | * Mac80211 callback. Sets slot time, ACK timeout and CTS timeout for given |
| 705 | * coverage class. The values are persistent, they are restored after device |
| 706 | * reset. |
| 707 | */ |
| 708 | static void |
Lorenzo Bianconi | a4bcaf5 | 2014-09-04 23:57:41 +0200 | [diff] [blame] | 709 | ath5k_set_coverage_class(struct ieee80211_hw *hw, s16 coverage_class) |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 710 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 711 | struct ath5k_hw *ah = hw->priv; |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 712 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 713 | mutex_lock(&ah->lock); |
| 714 | ath5k_hw_set_coverage_class(ah, coverage_class); |
| 715 | mutex_unlock(&ah->lock); |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | |
| 719 | static int |
| 720 | ath5k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant) |
| 721 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 722 | struct ath5k_hw *ah = hw->priv; |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 723 | |
| 724 | if (tx_ant == 1 && rx_ant == 1) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 725 | ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_FIXED_A); |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 726 | else if (tx_ant == 2 && rx_ant == 2) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 727 | ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_FIXED_B); |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 728 | else if ((tx_ant & 3) == 3 && (rx_ant & 3) == 3) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 729 | ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_DEFAULT); |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 730 | else |
| 731 | return -EINVAL; |
| 732 | return 0; |
| 733 | } |
| 734 | |
| 735 | |
| 736 | static int |
| 737 | ath5k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant) |
| 738 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 739 | struct ath5k_hw *ah = hw->priv; |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 740 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 741 | switch (ah->ah_ant_mode) { |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 742 | case AR5K_ANTMODE_FIXED_A: |
| 743 | *tx_ant = 1; *rx_ant = 1; break; |
| 744 | case AR5K_ANTMODE_FIXED_B: |
| 745 | *tx_ant = 2; *rx_ant = 2; break; |
| 746 | case AR5K_ANTMODE_DEFAULT: |
| 747 | *tx_ant = 3; *rx_ant = 3; break; |
| 748 | } |
| 749 | return 0; |
| 750 | } |
| 751 | |
| 752 | |
John W. Linville | 81266ba | 2011-03-07 16:32:59 -0500 | [diff] [blame] | 753 | static void ath5k_get_ringparam(struct ieee80211_hw *hw, |
| 754 | u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max) |
| 755 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 756 | struct ath5k_hw *ah = hw->priv; |
John W. Linville | 81266ba | 2011-03-07 16:32:59 -0500 | [diff] [blame] | 757 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 758 | *tx = ah->txqs[AR5K_TX_QUEUE_ID_DATA_MIN].txq_max; |
John W. Linville | 81266ba | 2011-03-07 16:32:59 -0500 | [diff] [blame] | 759 | |
| 760 | *tx_max = ATH5K_TXQ_LEN_MAX; |
| 761 | *rx = *rx_max = ATH_RXBUF; |
| 762 | } |
| 763 | |
| 764 | |
| 765 | static int ath5k_set_ringparam(struct ieee80211_hw *hw, u32 tx, u32 rx) |
| 766 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 767 | struct ath5k_hw *ah = hw->priv; |
John W. Linville | 81266ba | 2011-03-07 16:32:59 -0500 | [diff] [blame] | 768 | u16 qnum; |
| 769 | |
| 770 | /* only support setting tx ring size for now */ |
| 771 | if (rx != ATH_RXBUF) |
| 772 | return -EINVAL; |
| 773 | |
| 774 | /* restrict tx ring size min/max */ |
| 775 | if (!tx || tx > ATH5K_TXQ_LEN_MAX) |
| 776 | return -EINVAL; |
| 777 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 778 | for (qnum = 0; qnum < ARRAY_SIZE(ah->txqs); qnum++) { |
| 779 | if (!ah->txqs[qnum].setup) |
John W. Linville | 81266ba | 2011-03-07 16:32:59 -0500 | [diff] [blame] | 780 | continue; |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 781 | if (ah->txqs[qnum].qnum < AR5K_TX_QUEUE_ID_DATA_MIN || |
| 782 | ah->txqs[qnum].qnum > AR5K_TX_QUEUE_ID_DATA_MAX) |
John W. Linville | 81266ba | 2011-03-07 16:32:59 -0500 | [diff] [blame] | 783 | continue; |
| 784 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 785 | ah->txqs[qnum].txq_max = tx; |
| 786 | if (ah->txqs[qnum].txq_len >= ah->txqs[qnum].txq_max) |
| 787 | ieee80211_stop_queue(hw, ah->txqs[qnum].qnum); |
John W. Linville | 81266ba | 2011-03-07 16:32:59 -0500 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | return 0; |
| 791 | } |
| 792 | |
| 793 | |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 794 | const struct ieee80211_ops ath5k_hw_ops = { |
| 795 | .tx = ath5k_tx, |
| 796 | .start = ath5k_start, |
| 797 | .stop = ath5k_stop, |
| 798 | .add_interface = ath5k_add_interface, |
| 799 | /* .change_interface = not implemented */ |
| 800 | .remove_interface = ath5k_remove_interface, |
| 801 | .config = ath5k_config, |
| 802 | .bss_info_changed = ath5k_bss_info_changed, |
| 803 | .prepare_multicast = ath5k_prepare_multicast, |
| 804 | .configure_filter = ath5k_configure_filter, |
| 805 | /* .set_tim = not implemented */ |
| 806 | .set_key = ath5k_set_key, |
| 807 | /* .update_tkip_key = not implemented */ |
| 808 | /* .hw_scan = not implemented */ |
| 809 | .sw_scan_start = ath5k_sw_scan_start, |
| 810 | .sw_scan_complete = ath5k_sw_scan_complete, |
| 811 | .get_stats = ath5k_get_stats, |
| 812 | /* .get_tkip_seq = not implemented */ |
| 813 | /* .set_frag_threshold = not implemented */ |
| 814 | /* .set_rts_threshold = not implemented */ |
| 815 | /* .sta_add = not implemented */ |
| 816 | /* .sta_remove = not implemented */ |
| 817 | /* .sta_notify = not implemented */ |
| 818 | .conf_tx = ath5k_conf_tx, |
| 819 | .get_tsf = ath5k_get_tsf, |
| 820 | .set_tsf = ath5k_set_tsf, |
| 821 | .reset_tsf = ath5k_reset_tsf, |
| 822 | /* .tx_last_beacon = not implemented */ |
| 823 | /* .ampdu_action = not needed */ |
| 824 | .get_survey = ath5k_get_survey, |
| 825 | .set_coverage_class = ath5k_set_coverage_class, |
| 826 | /* .rfkill_poll = not implemented */ |
| 827 | /* .flush = not implemented */ |
| 828 | /* .channel_switch = not implemented */ |
| 829 | /* .napi_poll = not implemented */ |
| 830 | .set_antenna = ath5k_set_antenna, |
| 831 | .get_antenna = ath5k_get_antenna, |
John W. Linville | 81266ba | 2011-03-07 16:32:59 -0500 | [diff] [blame] | 832 | .set_ringparam = ath5k_set_ringparam, |
| 833 | .get_ringparam = ath5k_get_ringparam, |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 834 | }; |