Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2010 Atheros Communications Inc. |
| 3 | * |
| 4 | * Permission to use, copy, modify, and/or distribute this software for any |
| 5 | * purpose with or without fee is hereby granted, provided that the above |
| 6 | * copyright notice and this permission notice appear in all copies. |
| 7 | * |
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | */ |
| 16 | |
| 17 | #include "htc.h" |
| 18 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 19 | /*************/ |
| 20 | /* Utilities */ |
| 21 | /*************/ |
| 22 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 23 | /* HACK Alert: Use 11NG for 2.4, use 11NA for 5 */ |
| 24 | static enum htc_phymode ath9k_htc_get_curmode(struct ath9k_htc_priv *priv, |
| 25 | struct ath9k_channel *ichan) |
| 26 | { |
| 27 | enum htc_phymode mode; |
| 28 | |
| 29 | mode = HTC_MODE_AUTO; |
| 30 | |
| 31 | switch (ichan->chanmode) { |
| 32 | case CHANNEL_G: |
| 33 | case CHANNEL_G_HT20: |
| 34 | case CHANNEL_G_HT40PLUS: |
| 35 | case CHANNEL_G_HT40MINUS: |
| 36 | mode = HTC_MODE_11NG; |
| 37 | break; |
| 38 | case CHANNEL_A: |
| 39 | case CHANNEL_A_HT20: |
| 40 | case CHANNEL_A_HT40PLUS: |
| 41 | case CHANNEL_A_HT40MINUS: |
| 42 | mode = HTC_MODE_11NA; |
| 43 | break; |
| 44 | default: |
| 45 | break; |
| 46 | } |
| 47 | |
| 48 | return mode; |
| 49 | } |
| 50 | |
Sujith Manoharan | f933ebe | 2010-12-01 12:30:27 +0530 | [diff] [blame] | 51 | bool ath9k_htc_setpower(struct ath9k_htc_priv *priv, |
| 52 | enum ath9k_power_mode mode) |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 53 | { |
| 54 | bool ret; |
| 55 | |
| 56 | mutex_lock(&priv->htc_pm_lock); |
| 57 | ret = ath9k_hw_setpower(priv->ah, mode); |
| 58 | mutex_unlock(&priv->htc_pm_lock); |
| 59 | |
| 60 | return ret; |
| 61 | } |
| 62 | |
| 63 | void ath9k_htc_ps_wakeup(struct ath9k_htc_priv *priv) |
| 64 | { |
| 65 | mutex_lock(&priv->htc_pm_lock); |
| 66 | if (++priv->ps_usecount != 1) |
| 67 | goto unlock; |
| 68 | ath9k_hw_setpower(priv->ah, ATH9K_PM_AWAKE); |
| 69 | |
| 70 | unlock: |
| 71 | mutex_unlock(&priv->htc_pm_lock); |
| 72 | } |
| 73 | |
| 74 | void ath9k_htc_ps_restore(struct ath9k_htc_priv *priv) |
| 75 | { |
| 76 | mutex_lock(&priv->htc_pm_lock); |
| 77 | if (--priv->ps_usecount != 0) |
| 78 | goto unlock; |
| 79 | |
Vivek Natarajan | 8a8572a | 2010-04-27 13:05:37 +0530 | [diff] [blame] | 80 | if (priv->ps_idle) |
| 81 | ath9k_hw_setpower(priv->ah, ATH9K_PM_FULL_SLEEP); |
| 82 | else if (priv->ps_enabled) |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 83 | ath9k_hw_setpower(priv->ah, ATH9K_PM_NETWORK_SLEEP); |
Vivek Natarajan | 8a8572a | 2010-04-27 13:05:37 +0530 | [diff] [blame] | 84 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 85 | unlock: |
| 86 | mutex_unlock(&priv->htc_pm_lock); |
| 87 | } |
| 88 | |
| 89 | void ath9k_ps_work(struct work_struct *work) |
| 90 | { |
| 91 | struct ath9k_htc_priv *priv = |
| 92 | container_of(work, struct ath9k_htc_priv, |
| 93 | ps_work); |
| 94 | ath9k_htc_setpower(priv, ATH9K_PM_AWAKE); |
| 95 | |
| 96 | /* The chip wakes up after receiving the first beacon |
| 97 | while network sleep is enabled. For the driver to |
| 98 | be in sync with the hw, set the chip to awake and |
| 99 | only then set it to sleep. |
| 100 | */ |
| 101 | ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP); |
| 102 | } |
| 103 | |
Sujith Manoharan | 7c27734 | 2011-02-21 07:48:39 +0530 | [diff] [blame] | 104 | static void ath9k_htc_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif) |
| 105 | { |
| 106 | struct ath9k_htc_priv *priv = data; |
| 107 | struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; |
| 108 | |
Sujith Manoharan | a5fae37 | 2011-02-21 07:49:53 +0530 | [diff] [blame] | 109 | if ((vif->type == NL80211_IFTYPE_AP) && bss_conf->enable_beacon) |
| 110 | priv->reconfig_beacon = true; |
| 111 | |
Sujith Manoharan | 7c27734 | 2011-02-21 07:48:39 +0530 | [diff] [blame] | 112 | if (bss_conf->assoc) { |
| 113 | priv->rearm_ani = true; |
| 114 | priv->reconfig_beacon = true; |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | static void ath9k_htc_vif_reconfig(struct ath9k_htc_priv *priv) |
| 119 | { |
| 120 | priv->rearm_ani = false; |
| 121 | priv->reconfig_beacon = false; |
| 122 | |
| 123 | ieee80211_iterate_active_interfaces_atomic(priv->hw, |
| 124 | ath9k_htc_vif_iter, priv); |
| 125 | if (priv->rearm_ani) |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 126 | ath9k_htc_start_ani(priv); |
Sujith Manoharan | 7c27734 | 2011-02-21 07:48:39 +0530 | [diff] [blame] | 127 | |
| 128 | if (priv->reconfig_beacon) { |
| 129 | ath9k_htc_ps_wakeup(priv); |
| 130 | ath9k_htc_beacon_reconfig(priv); |
| 131 | ath9k_htc_ps_restore(priv); |
| 132 | } |
| 133 | } |
| 134 | |
Sujith Manoharan | 585895c | 2011-02-21 07:48:46 +0530 | [diff] [blame] | 135 | static void ath9k_htc_bssid_iter(void *data, u8 *mac, struct ieee80211_vif *vif) |
| 136 | { |
| 137 | struct ath9k_vif_iter_data *iter_data = data; |
| 138 | int i; |
| 139 | |
| 140 | for (i = 0; i < ETH_ALEN; i++) |
| 141 | iter_data->mask[i] &= ~(iter_data->hw_macaddr[i] ^ mac[i]); |
| 142 | } |
| 143 | |
| 144 | static void ath9k_htc_set_bssid_mask(struct ath9k_htc_priv *priv, |
| 145 | struct ieee80211_vif *vif) |
| 146 | { |
| 147 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 148 | struct ath9k_vif_iter_data iter_data; |
| 149 | |
| 150 | /* |
| 151 | * Use the hardware MAC address as reference, the hardware uses it |
| 152 | * together with the BSSID mask when matching addresses. |
| 153 | */ |
| 154 | iter_data.hw_macaddr = common->macaddr; |
| 155 | memset(&iter_data.mask, 0xff, ETH_ALEN); |
| 156 | |
| 157 | if (vif) |
| 158 | ath9k_htc_bssid_iter(&iter_data, vif->addr, vif); |
| 159 | |
| 160 | /* Get list of all active MAC addresses */ |
| 161 | ieee80211_iterate_active_interfaces_atomic(priv->hw, ath9k_htc_bssid_iter, |
| 162 | &iter_data); |
| 163 | |
| 164 | memcpy(common->bssidmask, iter_data.mask, ETH_ALEN); |
| 165 | ath_hw_setbssidmask(common); |
| 166 | } |
| 167 | |
Sujith Manoharan | ffbe7c8 | 2011-02-21 07:49:31 +0530 | [diff] [blame] | 168 | static void ath9k_htc_set_opmode(struct ath9k_htc_priv *priv) |
| 169 | { |
| 170 | if (priv->num_ibss_vif) |
| 171 | priv->ah->opmode = NL80211_IFTYPE_ADHOC; |
| 172 | else if (priv->num_ap_vif) |
| 173 | priv->ah->opmode = NL80211_IFTYPE_AP; |
| 174 | else |
| 175 | priv->ah->opmode = NL80211_IFTYPE_STATION; |
| 176 | |
| 177 | ath9k_hw_setopmode(priv->ah); |
| 178 | } |
| 179 | |
Sujith Manoharan | 7390867 | 2010-12-28 14:28:27 +0530 | [diff] [blame] | 180 | void ath9k_htc_reset(struct ath9k_htc_priv *priv) |
| 181 | { |
| 182 | struct ath_hw *ah = priv->ah; |
| 183 | struct ath_common *common = ath9k_hw_common(ah); |
| 184 | struct ieee80211_channel *channel = priv->hw->conf.channel; |
Rajkumar Manoharan | 4e3ae38 | 2011-01-15 01:33:28 +0530 | [diff] [blame] | 185 | struct ath9k_hw_cal_data *caldata = NULL; |
Sujith Manoharan | 7390867 | 2010-12-28 14:28:27 +0530 | [diff] [blame] | 186 | enum htc_phymode mode; |
| 187 | __be16 htc_mode; |
| 188 | u8 cmd_rsp; |
| 189 | int ret; |
| 190 | |
| 191 | mutex_lock(&priv->mutex); |
| 192 | ath9k_htc_ps_wakeup(priv); |
| 193 | |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 194 | ath9k_htc_stop_ani(priv); |
Sujith Manoharan | 7390867 | 2010-12-28 14:28:27 +0530 | [diff] [blame] | 195 | ieee80211_stop_queues(priv->hw); |
Sujith Manoharan | b587fc8 | 2011-04-13 11:25:59 +0530 | [diff] [blame] | 196 | |
Sujith Manoharan | 859c3ca | 2011-04-13 11:26:39 +0530 | [diff] [blame] | 197 | del_timer_sync(&priv->tx.cleanup_timer); |
Sujith Manoharan | b587fc8 | 2011-04-13 11:25:59 +0530 | [diff] [blame] | 198 | ath9k_htc_tx_drain(priv); |
| 199 | |
Sujith Manoharan | 7390867 | 2010-12-28 14:28:27 +0530 | [diff] [blame] | 200 | WMI_CMD(WMI_DISABLE_INTR_CMDID); |
| 201 | WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID); |
| 202 | WMI_CMD(WMI_STOP_RECV_CMDID); |
| 203 | |
Sujith Manoharan | f4c8899 | 2011-04-13 11:23:52 +0530 | [diff] [blame] | 204 | ath9k_wmi_event_drain(priv); |
| 205 | |
Rajkumar Manoharan | 4e3ae38 | 2011-01-15 01:33:28 +0530 | [diff] [blame] | 206 | caldata = &priv->caldata; |
Sujith Manoharan | 7390867 | 2010-12-28 14:28:27 +0530 | [diff] [blame] | 207 | ret = ath9k_hw_reset(ah, ah->curchan, caldata, false); |
| 208 | if (ret) { |
| 209 | ath_err(common, |
| 210 | "Unable to reset device (%u Mhz) reset status %d\n", |
| 211 | channel->center_freq, ret); |
| 212 | } |
| 213 | |
Rajkumar Manoharan | b2a5c3d | 2011-01-31 23:47:45 +0530 | [diff] [blame] | 214 | ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit, |
| 215 | &priv->curtxpow); |
Sujith Manoharan | 7390867 | 2010-12-28 14:28:27 +0530 | [diff] [blame] | 216 | |
| 217 | WMI_CMD(WMI_START_RECV_CMDID); |
| 218 | ath9k_host_rx_init(priv); |
| 219 | |
| 220 | mode = ath9k_htc_get_curmode(priv, ah->curchan); |
| 221 | htc_mode = cpu_to_be16(mode); |
| 222 | WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode); |
| 223 | |
| 224 | WMI_CMD(WMI_ENABLE_INTR_CMDID); |
| 225 | htc_start(priv->htc); |
Sujith Manoharan | 7c27734 | 2011-02-21 07:48:39 +0530 | [diff] [blame] | 226 | ath9k_htc_vif_reconfig(priv); |
Sujith Manoharan | 7390867 | 2010-12-28 14:28:27 +0530 | [diff] [blame] | 227 | ieee80211_wake_queues(priv->hw); |
| 228 | |
Sujith Manoharan | 859c3ca | 2011-04-13 11:26:39 +0530 | [diff] [blame] | 229 | mod_timer(&priv->tx.cleanup_timer, |
| 230 | jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL)); |
| 231 | |
Sujith Manoharan | 7390867 | 2010-12-28 14:28:27 +0530 | [diff] [blame] | 232 | ath9k_htc_ps_restore(priv); |
| 233 | mutex_unlock(&priv->mutex); |
| 234 | } |
| 235 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 236 | static int ath9k_htc_set_channel(struct ath9k_htc_priv *priv, |
| 237 | struct ieee80211_hw *hw, |
| 238 | struct ath9k_channel *hchan) |
| 239 | { |
| 240 | struct ath_hw *ah = priv->ah; |
| 241 | struct ath_common *common = ath9k_hw_common(ah); |
| 242 | struct ieee80211_conf *conf = &common->hw->conf; |
Sujith Manoharan | 039a072 | 2010-12-28 14:28:37 +0530 | [diff] [blame] | 243 | bool fastcc; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 244 | struct ieee80211_channel *channel = hw->conf.channel; |
Vivek Natarajan | 8354dd3 | 2011-02-18 16:09:51 +0530 | [diff] [blame] | 245 | struct ath9k_hw_cal_data *caldata = NULL; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 246 | enum htc_phymode mode; |
Sujith | 7f1f5a0 | 2010-04-16 11:54:03 +0530 | [diff] [blame] | 247 | __be16 htc_mode; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 248 | u8 cmd_rsp; |
| 249 | int ret; |
| 250 | |
| 251 | if (priv->op_flags & OP_INVALID) |
| 252 | return -EIO; |
| 253 | |
Sujith Manoharan | 039a072 | 2010-12-28 14:28:37 +0530 | [diff] [blame] | 254 | fastcc = !!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 255 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 256 | ath9k_htc_ps_wakeup(priv); |
Sujith Manoharan | b587fc8 | 2011-04-13 11:25:59 +0530 | [diff] [blame] | 257 | |
Sujith Manoharan | 859c3ca | 2011-04-13 11:26:39 +0530 | [diff] [blame] | 258 | del_timer_sync(&priv->tx.cleanup_timer); |
Sujith Manoharan | b587fc8 | 2011-04-13 11:25:59 +0530 | [diff] [blame] | 259 | ath9k_htc_tx_drain(priv); |
| 260 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 261 | WMI_CMD(WMI_DISABLE_INTR_CMDID); |
| 262 | WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID); |
| 263 | WMI_CMD(WMI_STOP_RECV_CMDID); |
| 264 | |
Sujith Manoharan | f4c8899 | 2011-04-13 11:23:52 +0530 | [diff] [blame] | 265 | ath9k_wmi_event_drain(priv); |
| 266 | |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 267 | ath_dbg(common, ATH_DBG_CONFIG, |
| 268 | "(%u MHz) -> (%u MHz), HT: %d, HT40: %d fastcc: %d\n", |
| 269 | priv->ah->curchan->channel, |
| 270 | channel->center_freq, conf_is_ht(conf), conf_is_ht40(conf), |
| 271 | fastcc); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 272 | |
Rajkumar Manoharan | 4e3ae38 | 2011-01-15 01:33:28 +0530 | [diff] [blame] | 273 | if (!fastcc) |
| 274 | caldata = &priv->caldata; |
Sujith Manoharan | b587fc8 | 2011-04-13 11:25:59 +0530 | [diff] [blame] | 275 | |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 276 | ret = ath9k_hw_reset(ah, hchan, caldata, fastcc); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 277 | if (ret) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 278 | ath_err(common, |
| 279 | "Unable to reset channel (%u Mhz) reset status %d\n", |
| 280 | channel->center_freq, ret); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 281 | goto err; |
| 282 | } |
| 283 | |
Rajkumar Manoharan | b2a5c3d | 2011-01-31 23:47:45 +0530 | [diff] [blame] | 284 | ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit, |
| 285 | &priv->curtxpow); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 286 | |
| 287 | WMI_CMD(WMI_START_RECV_CMDID); |
| 288 | if (ret) |
| 289 | goto err; |
| 290 | |
| 291 | ath9k_host_rx_init(priv); |
| 292 | |
| 293 | mode = ath9k_htc_get_curmode(priv, hchan); |
| 294 | htc_mode = cpu_to_be16(mode); |
| 295 | WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode); |
| 296 | if (ret) |
| 297 | goto err; |
| 298 | |
| 299 | WMI_CMD(WMI_ENABLE_INTR_CMDID); |
| 300 | if (ret) |
| 301 | goto err; |
| 302 | |
| 303 | htc_start(priv->htc); |
Sujith Manoharan | a5fae37 | 2011-02-21 07:49:53 +0530 | [diff] [blame] | 304 | |
| 305 | if (!(priv->op_flags & OP_SCANNING) && |
| 306 | !(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)) |
| 307 | ath9k_htc_vif_reconfig(priv); |
| 308 | |
Sujith Manoharan | 859c3ca | 2011-04-13 11:26:39 +0530 | [diff] [blame] | 309 | mod_timer(&priv->tx.cleanup_timer, |
| 310 | jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL)); |
| 311 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 312 | err: |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 313 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 314 | return ret; |
| 315 | } |
| 316 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 317 | /* |
| 318 | * Monitor mode handling is a tad complicated because the firmware requires |
| 319 | * an interface to be created exclusively, while mac80211 doesn't associate |
| 320 | * an interface with the mode. |
| 321 | * |
| 322 | * So, for now, only one monitor interface can be configured. |
| 323 | */ |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 324 | static void __ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv) |
Rajkumar Manoharan | 81fc2a3 | 2010-11-26 23:24:33 +0530 | [diff] [blame] | 325 | { |
| 326 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 327 | struct ath9k_htc_target_vif hvif; |
| 328 | int ret = 0; |
| 329 | u8 cmd_rsp; |
| 330 | |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 331 | memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif)); |
| 332 | memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN); |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 333 | hvif.index = priv->mon_vif_idx; |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 334 | WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif); |
Sujith Manoharan | 0ff2b5c | 2011-04-20 11:00:34 +0530 | [diff] [blame] | 335 | if (ret) { |
| 336 | ath_err(common, "Unable to remove monitor interface at idx: %d\n", |
| 337 | priv->mon_vif_idx); |
| 338 | } |
| 339 | |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 340 | priv->nvifs--; |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 341 | priv->vif_slot &= ~(1 << priv->mon_vif_idx); |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | static int ath9k_htc_add_monitor_interface(struct ath9k_htc_priv *priv) |
| 345 | { |
| 346 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 347 | struct ath9k_htc_target_vif hvif; |
| 348 | struct ath9k_htc_target_sta tsta; |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 349 | int ret = 0, sta_idx; |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 350 | u8 cmd_rsp; |
| 351 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 352 | if ((priv->nvifs >= ATH9K_HTC_MAX_VIF) || |
| 353 | (priv->nstations >= ATH9K_HTC_MAX_STA)) { |
| 354 | ret = -ENOBUFS; |
| 355 | goto err_vif; |
| 356 | } |
Rajkumar Manoharan | 81fc2a3 | 2010-11-26 23:24:33 +0530 | [diff] [blame] | 357 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 358 | sta_idx = ffz(priv->sta_slot); |
| 359 | if ((sta_idx < 0) || (sta_idx > ATH9K_HTC_MAX_STA)) { |
| 360 | ret = -ENOBUFS; |
| 361 | goto err_vif; |
| 362 | } |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 363 | |
| 364 | /* |
| 365 | * Add an interface. |
| 366 | */ |
Rajkumar Manoharan | 81fc2a3 | 2010-11-26 23:24:33 +0530 | [diff] [blame] | 367 | memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif)); |
| 368 | memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN); |
| 369 | |
Sujith Manoharan | e4c6250 | 2011-04-13 11:24:43 +0530 | [diff] [blame] | 370 | hvif.opmode = HTC_M_MONITOR; |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 371 | hvif.index = ffz(priv->vif_slot); |
Rajkumar Manoharan | 81fc2a3 | 2010-11-26 23:24:33 +0530 | [diff] [blame] | 372 | |
| 373 | WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif); |
| 374 | if (ret) |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 375 | goto err_vif; |
| 376 | |
| 377 | /* |
| 378 | * Assign the monitor interface index as a special case here. |
| 379 | * This is needed when the interface is brought down. |
| 380 | */ |
| 381 | priv->mon_vif_idx = hvif.index; |
| 382 | priv->vif_slot |= (1 << hvif.index); |
| 383 | |
| 384 | /* |
| 385 | * Set the hardware mode to monitor only if there are no |
| 386 | * other interfaces. |
| 387 | */ |
| 388 | if (!priv->nvifs) |
| 389 | priv->ah->opmode = NL80211_IFTYPE_MONITOR; |
Rajkumar Manoharan | 81fc2a3 | 2010-11-26 23:24:33 +0530 | [diff] [blame] | 390 | |
| 391 | priv->nvifs++; |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 392 | |
| 393 | /* |
| 394 | * Associate a station with the interface for packet injection. |
| 395 | */ |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 396 | memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta)); |
| 397 | |
| 398 | memcpy(&tsta.macaddr, common->macaddr, ETH_ALEN); |
| 399 | |
| 400 | tsta.is_vif_sta = 1; |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 401 | tsta.sta_index = sta_idx; |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 402 | tsta.vif_index = hvif.index; |
Sujith Manoharan | b97c57f | 2011-04-13 11:24:37 +0530 | [diff] [blame] | 403 | tsta.maxampdu = cpu_to_be16(0xffff); |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 404 | |
| 405 | WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta); |
| 406 | if (ret) { |
| 407 | ath_err(common, "Unable to add station entry for monitor mode\n"); |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 408 | goto err_sta; |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 409 | } |
| 410 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 411 | priv->sta_slot |= (1 << sta_idx); |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 412 | priv->nstations++; |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 413 | priv->vif_sta_pos[priv->mon_vif_idx] = sta_idx; |
Sujith Manoharan | 55de80d | 2011-01-05 01:06:21 +0530 | [diff] [blame] | 414 | priv->ah->is_monitoring = true; |
| 415 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 416 | ath_dbg(common, ATH_DBG_CONFIG, |
| 417 | "Attached a monitor interface at idx: %d, sta idx: %d\n", |
| 418 | priv->mon_vif_idx, sta_idx); |
| 419 | |
Rajkumar Manoharan | 81fc2a3 | 2010-11-26 23:24:33 +0530 | [diff] [blame] | 420 | return 0; |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 421 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 422 | err_sta: |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 423 | /* |
| 424 | * Remove the interface from the target. |
| 425 | */ |
| 426 | __ath9k_htc_remove_monitor_interface(priv); |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 427 | err_vif: |
| 428 | ath_dbg(common, ATH_DBG_FATAL, "Unable to attach a monitor interface\n"); |
| 429 | |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 430 | return ret; |
Rajkumar Manoharan | 81fc2a3 | 2010-11-26 23:24:33 +0530 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | static int ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv) |
| 434 | { |
| 435 | struct ath_common *common = ath9k_hw_common(priv->ah); |
Rajkumar Manoharan | 81fc2a3 | 2010-11-26 23:24:33 +0530 | [diff] [blame] | 436 | int ret = 0; |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 437 | u8 cmd_rsp, sta_idx; |
Rajkumar Manoharan | 81fc2a3 | 2010-11-26 23:24:33 +0530 | [diff] [blame] | 438 | |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 439 | __ath9k_htc_remove_monitor_interface(priv); |
Rajkumar Manoharan | 81fc2a3 | 2010-11-26 23:24:33 +0530 | [diff] [blame] | 440 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 441 | sta_idx = priv->vif_sta_pos[priv->mon_vif_idx]; |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 442 | |
| 443 | WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx); |
| 444 | if (ret) { |
| 445 | ath_err(common, "Unable to remove station entry for monitor mode\n"); |
| 446 | return ret; |
| 447 | } |
| 448 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 449 | priv->sta_slot &= ~(1 << sta_idx); |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 450 | priv->nstations--; |
Sujith Manoharan | 55de80d | 2011-01-05 01:06:21 +0530 | [diff] [blame] | 451 | priv->ah->is_monitoring = false; |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 452 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 453 | ath_dbg(common, ATH_DBG_CONFIG, |
| 454 | "Removed a monitor interface at idx: %d, sta idx: %d\n", |
| 455 | priv->mon_vif_idx, sta_idx); |
| 456 | |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 457 | return 0; |
Rajkumar Manoharan | 81fc2a3 | 2010-11-26 23:24:33 +0530 | [diff] [blame] | 458 | } |
| 459 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 460 | static int ath9k_htc_add_station(struct ath9k_htc_priv *priv, |
| 461 | struct ieee80211_vif *vif, |
| 462 | struct ieee80211_sta *sta) |
| 463 | { |
| 464 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 465 | struct ath9k_htc_target_sta tsta; |
| 466 | struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv; |
| 467 | struct ath9k_htc_sta *ista; |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 468 | int ret, sta_idx; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 469 | u8 cmd_rsp; |
Sujith Manoharan | f0dd498 | 2011-04-20 11:01:00 +0530 | [diff] [blame] | 470 | u16 maxampdu; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 471 | |
| 472 | if (priv->nstations >= ATH9K_HTC_MAX_STA) |
| 473 | return -ENOBUFS; |
| 474 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 475 | sta_idx = ffz(priv->sta_slot); |
| 476 | if ((sta_idx < 0) || (sta_idx > ATH9K_HTC_MAX_STA)) |
| 477 | return -ENOBUFS; |
| 478 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 479 | memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta)); |
| 480 | |
| 481 | if (sta) { |
| 482 | ista = (struct ath9k_htc_sta *) sta->drv_priv; |
| 483 | memcpy(&tsta.macaddr, sta->addr, ETH_ALEN); |
| 484 | memcpy(&tsta.bssid, common->curbssid, ETH_ALEN); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 485 | tsta.is_vif_sta = 0; |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 486 | ista->index = sta_idx; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 487 | } else { |
| 488 | memcpy(&tsta.macaddr, vif->addr, ETH_ALEN); |
| 489 | tsta.is_vif_sta = 1; |
| 490 | } |
| 491 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 492 | tsta.sta_index = sta_idx; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 493 | tsta.vif_index = avp->index; |
Sujith Manoharan | f0dd498 | 2011-04-20 11:01:00 +0530 | [diff] [blame] | 494 | |
| 495 | if (!sta) { |
| 496 | tsta.maxampdu = cpu_to_be16(0xffff); |
| 497 | } else { |
| 498 | maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR + |
| 499 | sta->ht_cap.ampdu_factor); |
| 500 | tsta.maxampdu = cpu_to_be16(maxampdu); |
| 501 | } |
| 502 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 503 | if (sta && sta->ht_cap.ht_supported) |
| 504 | tsta.flags = cpu_to_be16(ATH_HTC_STA_HT); |
| 505 | |
| 506 | WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta); |
| 507 | if (ret) { |
| 508 | if (sta) |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 509 | ath_err(common, |
| 510 | "Unable to add station entry for: %pM\n", |
| 511 | sta->addr); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 512 | return ret; |
| 513 | } |
| 514 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 515 | if (sta) { |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 516 | ath_dbg(common, ATH_DBG_CONFIG, |
| 517 | "Added a station entry for: %pM (idx: %d)\n", |
| 518 | sta->addr, tsta.sta_index); |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 519 | } else { |
| 520 | ath_dbg(common, ATH_DBG_CONFIG, |
| 521 | "Added a station entry for VIF %d (idx: %d)\n", |
| 522 | avp->index, tsta.sta_index); |
| 523 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 524 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 525 | priv->sta_slot |= (1 << sta_idx); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 526 | priv->nstations++; |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 527 | if (!sta) |
| 528 | priv->vif_sta_pos[avp->index] = sta_idx; |
| 529 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 530 | return 0; |
| 531 | } |
| 532 | |
| 533 | static int ath9k_htc_remove_station(struct ath9k_htc_priv *priv, |
| 534 | struct ieee80211_vif *vif, |
| 535 | struct ieee80211_sta *sta) |
| 536 | { |
| 537 | struct ath_common *common = ath9k_hw_common(priv->ah); |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 538 | struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 539 | struct ath9k_htc_sta *ista; |
| 540 | int ret; |
| 541 | u8 cmd_rsp, sta_idx; |
| 542 | |
| 543 | if (sta) { |
| 544 | ista = (struct ath9k_htc_sta *) sta->drv_priv; |
| 545 | sta_idx = ista->index; |
| 546 | } else { |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 547 | sta_idx = priv->vif_sta_pos[avp->index]; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx); |
| 551 | if (ret) { |
| 552 | if (sta) |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 553 | ath_err(common, |
| 554 | "Unable to remove station entry for: %pM\n", |
| 555 | sta->addr); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 556 | return ret; |
| 557 | } |
| 558 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 559 | if (sta) { |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 560 | ath_dbg(common, ATH_DBG_CONFIG, |
| 561 | "Removed a station entry for: %pM (idx: %d)\n", |
| 562 | sta->addr, sta_idx); |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 563 | } else { |
| 564 | ath_dbg(common, ATH_DBG_CONFIG, |
| 565 | "Removed a station entry for VIF %d (idx: %d)\n", |
| 566 | avp->index, sta_idx); |
| 567 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 568 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 569 | priv->sta_slot &= ~(1 << sta_idx); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 570 | priv->nstations--; |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 571 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 572 | return 0; |
| 573 | } |
| 574 | |
Sujith Manoharan | 3a0593e | 2011-04-20 14:33:28 +0530 | [diff] [blame] | 575 | int ath9k_htc_update_cap_target(struct ath9k_htc_priv *priv, |
| 576 | u8 enable_coex) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 577 | { |
| 578 | struct ath9k_htc_cap_target tcap; |
| 579 | int ret; |
| 580 | u8 cmd_rsp; |
| 581 | |
| 582 | memset(&tcap, 0, sizeof(struct ath9k_htc_cap_target)); |
| 583 | |
Sujith Manoharan | 3a0593e | 2011-04-20 14:33:28 +0530 | [diff] [blame] | 584 | tcap.ampdu_limit = cpu_to_be32(0xffff); |
| 585 | tcap.ampdu_subframes = priv->hw->max_tx_aggregation_subframes; |
| 586 | tcap.enable_coex = enable_coex; |
Sujith | 29d9075 | 2010-06-02 15:53:43 +0530 | [diff] [blame] | 587 | tcap.tx_chainmask = priv->ah->caps.tx_chainmask; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 588 | |
| 589 | WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID, &tcap); |
| 590 | |
| 591 | return ret; |
| 592 | } |
| 593 | |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 594 | static void ath9k_htc_setup_rate(struct ath9k_htc_priv *priv, |
| 595 | struct ieee80211_sta *sta, |
| 596 | struct ath9k_htc_target_rate *trate) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 597 | { |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 598 | struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv; |
| 599 | struct ieee80211_supported_band *sband; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 600 | u32 caps = 0; |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 601 | int i, j; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 602 | |
Sujith | ea46e64 | 2010-06-02 15:53:50 +0530 | [diff] [blame] | 603 | sband = priv->hw->wiphy->bands[priv->hw->conf.channel->band]; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 604 | |
| 605 | for (i = 0, j = 0; i < sband->n_bitrates; i++) { |
| 606 | if (sta->supp_rates[sband->band] & BIT(i)) { |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 607 | trate->rates.legacy_rates.rs_rates[j] |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 608 | = (sband->bitrates[i].bitrate * 2) / 10; |
| 609 | j++; |
| 610 | } |
| 611 | } |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 612 | trate->rates.legacy_rates.rs_nrates = j; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 613 | |
| 614 | if (sta->ht_cap.ht_supported) { |
| 615 | for (i = 0, j = 0; i < 77; i++) { |
| 616 | if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8))) |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 617 | trate->rates.ht_rates.rs_rates[j++] = i; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 618 | if (j == ATH_HTC_RATE_MAX) |
| 619 | break; |
| 620 | } |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 621 | trate->rates.ht_rates.rs_nrates = j; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 622 | |
| 623 | caps = WLAN_RC_HT_FLAG; |
Felix Fietkau | 3553727 | 2010-06-12 17:22:33 +0200 | [diff] [blame] | 624 | if (sta->ht_cap.mcs.rx_mask[1]) |
| 625 | caps |= WLAN_RC_DS_FLAG; |
Vivek Natarajan | 71ba186 | 2010-08-12 14:23:28 +0530 | [diff] [blame] | 626 | if ((sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) && |
| 627 | (conf_is_ht40(&priv->hw->conf))) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 628 | caps |= WLAN_RC_40_FLAG; |
Sujith | b4dec5e | 2010-05-17 12:01:19 +0530 | [diff] [blame] | 629 | if (conf_is_ht40(&priv->hw->conf) && |
| 630 | (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40)) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 631 | caps |= WLAN_RC_SGI_FLAG; |
Sujith | b4dec5e | 2010-05-17 12:01:19 +0530 | [diff] [blame] | 632 | else if (conf_is_ht20(&priv->hw->conf) && |
| 633 | (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20)) |
| 634 | caps |= WLAN_RC_SGI_FLAG; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 635 | } |
| 636 | |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 637 | trate->sta_index = ista->index; |
| 638 | trate->isnew = 1; |
| 639 | trate->capflags = cpu_to_be32(caps); |
| 640 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 641 | |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 642 | static int ath9k_htc_send_rate_cmd(struct ath9k_htc_priv *priv, |
| 643 | struct ath9k_htc_target_rate *trate) |
| 644 | { |
| 645 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 646 | int ret; |
| 647 | u8 cmd_rsp; |
| 648 | |
| 649 | WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID, trate); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 650 | if (ret) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 651 | ath_err(common, |
| 652 | "Unable to initialize Rate information on target\n"); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 653 | } |
| 654 | |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 655 | return ret; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 656 | } |
| 657 | |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 658 | static void ath9k_htc_init_rate(struct ath9k_htc_priv *priv, |
| 659 | struct ieee80211_sta *sta) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 660 | { |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 661 | struct ath_common *common = ath9k_hw_common(priv->ah); |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 662 | struct ath9k_htc_target_rate trate; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 663 | int ret; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 664 | |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 665 | memset(&trate, 0, sizeof(struct ath9k_htc_target_rate)); |
| 666 | ath9k_htc_setup_rate(priv, sta, &trate); |
| 667 | ret = ath9k_htc_send_rate_cmd(priv, &trate); |
| 668 | if (!ret) |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 669 | ath_dbg(common, ATH_DBG_CONFIG, |
| 670 | "Updated target sta: %pM, rate caps: 0x%X\n", |
| 671 | sta->addr, be32_to_cpu(trate.capflags)); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 672 | } |
| 673 | |
Sujith | 2c76ef8 | 2010-05-17 12:01:18 +0530 | [diff] [blame] | 674 | static void ath9k_htc_update_rate(struct ath9k_htc_priv *priv, |
| 675 | struct ieee80211_vif *vif, |
| 676 | struct ieee80211_bss_conf *bss_conf) |
| 677 | { |
| 678 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 679 | struct ath9k_htc_target_rate trate; |
| 680 | struct ieee80211_sta *sta; |
| 681 | int ret; |
| 682 | |
| 683 | memset(&trate, 0, sizeof(struct ath9k_htc_target_rate)); |
| 684 | |
| 685 | rcu_read_lock(); |
| 686 | sta = ieee80211_find_sta(vif, bss_conf->bssid); |
| 687 | if (!sta) { |
| 688 | rcu_read_unlock(); |
| 689 | return; |
| 690 | } |
| 691 | ath9k_htc_setup_rate(priv, sta, &trate); |
| 692 | rcu_read_unlock(); |
| 693 | |
| 694 | ret = ath9k_htc_send_rate_cmd(priv, &trate); |
| 695 | if (!ret) |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 696 | ath_dbg(common, ATH_DBG_CONFIG, |
| 697 | "Updated target sta: %pM, rate caps: 0x%X\n", |
| 698 | bss_conf->bssid, be32_to_cpu(trate.capflags)); |
Sujith | 2c76ef8 | 2010-05-17 12:01:18 +0530 | [diff] [blame] | 699 | } |
| 700 | |
Luis R. Rodriguez | 9edd952 | 2010-07-13 21:27:25 -0400 | [diff] [blame] | 701 | static int ath9k_htc_tx_aggr_oper(struct ath9k_htc_priv *priv, |
| 702 | struct ieee80211_vif *vif, |
| 703 | struct ieee80211_sta *sta, |
| 704 | enum ieee80211_ampdu_mlme_action action, |
| 705 | u16 tid) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 706 | { |
| 707 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 708 | struct ath9k_htc_target_aggr aggr; |
Dan Carpenter | 277a64d | 2010-05-08 18:23:20 +0200 | [diff] [blame] | 709 | struct ath9k_htc_sta *ista; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 710 | int ret = 0; |
| 711 | u8 cmd_rsp; |
| 712 | |
Dan Carpenter | 0730d11 | 2010-05-08 18:24:02 +0200 | [diff] [blame] | 713 | if (tid >= ATH9K_HTC_MAX_TID) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 714 | return -EINVAL; |
| 715 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 716 | memset(&aggr, 0, sizeof(struct ath9k_htc_target_aggr)); |
Sujith | ef98c3c | 2010-03-29 16:07:11 +0530 | [diff] [blame] | 717 | ista = (struct ath9k_htc_sta *) sta->drv_priv; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 718 | |
Sujith | ef98c3c | 2010-03-29 16:07:11 +0530 | [diff] [blame] | 719 | aggr.sta_index = ista->index; |
Sujith | d7ca213 | 2010-06-15 10:24:37 +0530 | [diff] [blame] | 720 | aggr.tidno = tid & 0xf; |
| 721 | aggr.aggr_enable = (action == IEEE80211_AMPDU_TX_START) ? true : false; |
Sujith | ef98c3c | 2010-03-29 16:07:11 +0530 | [diff] [blame] | 722 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 723 | WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID, &aggr); |
| 724 | if (ret) |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 725 | ath_dbg(common, ATH_DBG_CONFIG, |
| 726 | "Unable to %s TX aggregation for (%pM, %d)\n", |
| 727 | (aggr.aggr_enable) ? "start" : "stop", sta->addr, tid); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 728 | else |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 729 | ath_dbg(common, ATH_DBG_CONFIG, |
| 730 | "%s TX aggregation for (%pM, %d)\n", |
| 731 | (aggr.aggr_enable) ? "Starting" : "Stopping", |
| 732 | sta->addr, tid); |
Sujith | d7ca213 | 2010-06-15 10:24:37 +0530 | [diff] [blame] | 733 | |
Sujith Manoharan | 658ef04 | 2011-04-13 11:25:00 +0530 | [diff] [blame] | 734 | spin_lock_bh(&priv->tx.tx_lock); |
Sujith | d7ca213 | 2010-06-15 10:24:37 +0530 | [diff] [blame] | 735 | ista->tid_state[tid] = (aggr.aggr_enable && !ret) ? AGGR_START : AGGR_STOP; |
Sujith Manoharan | 658ef04 | 2011-04-13 11:25:00 +0530 | [diff] [blame] | 736 | spin_unlock_bh(&priv->tx.tx_lock); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 737 | |
| 738 | return ret; |
| 739 | } |
| 740 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 741 | /*******/ |
| 742 | /* ANI */ |
| 743 | /*******/ |
| 744 | |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 745 | void ath9k_htc_start_ani(struct ath9k_htc_priv *priv) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 746 | { |
| 747 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 748 | unsigned long timestamp = jiffies_to_msecs(jiffies); |
| 749 | |
| 750 | common->ani.longcal_timer = timestamp; |
| 751 | common->ani.shortcal_timer = timestamp; |
| 752 | common->ani.checkani_timer = timestamp; |
| 753 | |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 754 | priv->op_flags |= OP_ANI_RUNNING; |
| 755 | |
| 756 | ieee80211_queue_delayed_work(common->hw, &priv->ani_work, |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 757 | msecs_to_jiffies(ATH_ANI_POLLINTERVAL)); |
| 758 | } |
| 759 | |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 760 | void ath9k_htc_stop_ani(struct ath9k_htc_priv *priv) |
| 761 | { |
| 762 | cancel_delayed_work_sync(&priv->ani_work); |
| 763 | priv->op_flags &= ~OP_ANI_RUNNING; |
| 764 | } |
| 765 | |
| 766 | void ath9k_htc_ani_work(struct work_struct *work) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 767 | { |
| 768 | struct ath9k_htc_priv *priv = |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 769 | container_of(work, struct ath9k_htc_priv, ani_work.work); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 770 | struct ath_hw *ah = priv->ah; |
| 771 | struct ath_common *common = ath9k_hw_common(ah); |
| 772 | bool longcal = false; |
| 773 | bool shortcal = false; |
| 774 | bool aniflag = false; |
| 775 | unsigned int timestamp = jiffies_to_msecs(jiffies); |
| 776 | u32 cal_interval, short_cal_interval; |
| 777 | |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 778 | short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ? |
| 779 | ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 780 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 781 | /* Only calibrate if awake */ |
| 782 | if (ah->power_mode != ATH9K_PM_AWAKE) |
| 783 | goto set_timer; |
| 784 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 785 | /* Long calibration runs independently of short calibration. */ |
| 786 | if ((timestamp - common->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) { |
| 787 | longcal = true; |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 788 | ath_dbg(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 789 | common->ani.longcal_timer = timestamp; |
| 790 | } |
| 791 | |
| 792 | /* Short calibration applies only while caldone is false */ |
| 793 | if (!common->ani.caldone) { |
| 794 | if ((timestamp - common->ani.shortcal_timer) >= |
| 795 | short_cal_interval) { |
| 796 | shortcal = true; |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 797 | ath_dbg(common, ATH_DBG_ANI, |
| 798 | "shortcal @%lu\n", jiffies); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 799 | common->ani.shortcal_timer = timestamp; |
| 800 | common->ani.resetcal_timer = timestamp; |
| 801 | } |
| 802 | } else { |
| 803 | if ((timestamp - common->ani.resetcal_timer) >= |
| 804 | ATH_RESTART_CALINTERVAL) { |
| 805 | common->ani.caldone = ath9k_hw_reset_calvalid(ah); |
| 806 | if (common->ani.caldone) |
| 807 | common->ani.resetcal_timer = timestamp; |
| 808 | } |
| 809 | } |
| 810 | |
| 811 | /* Verify whether we must check ANI */ |
| 812 | if ((timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) { |
| 813 | aniflag = true; |
| 814 | common->ani.checkani_timer = timestamp; |
| 815 | } |
| 816 | |
| 817 | /* Skip all processing if there's nothing to do. */ |
| 818 | if (longcal || shortcal || aniflag) { |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 819 | |
| 820 | ath9k_htc_ps_wakeup(priv); |
| 821 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 822 | /* Call ANI routine if necessary */ |
| 823 | if (aniflag) |
| 824 | ath9k_hw_ani_monitor(ah, ah->curchan); |
| 825 | |
| 826 | /* Perform calibration if necessary */ |
Felix Fietkau | 35ecfe0 | 2010-09-29 17:15:26 +0200 | [diff] [blame] | 827 | if (longcal || shortcal) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 828 | common->ani.caldone = |
| 829 | ath9k_hw_calibrate(ah, ah->curchan, |
| 830 | common->rx_chainmask, |
| 831 | longcal); |
| 832 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 833 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 834 | } |
| 835 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 836 | set_timer: |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 837 | /* |
| 838 | * Set timer interval based on previous results. |
| 839 | * The interval must be the shortest necessary to satisfy ANI, |
| 840 | * short calibration and long calibration. |
| 841 | */ |
| 842 | cal_interval = ATH_LONG_CALINTERVAL; |
| 843 | if (priv->ah->config.enable_ani) |
| 844 | cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL); |
| 845 | if (!common->ani.caldone) |
| 846 | cal_interval = min(cal_interval, (u32)short_cal_interval); |
| 847 | |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 848 | ieee80211_queue_delayed_work(common->hw, &priv->ani_work, |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 849 | msecs_to_jiffies(cal_interval)); |
| 850 | } |
| 851 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 852 | /**********************/ |
| 853 | /* mac80211 Callbacks */ |
| 854 | /**********************/ |
| 855 | |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 856 | static void ath9k_htc_tx(struct ieee80211_hw *hw, struct sk_buff *skb) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 857 | { |
| 858 | struct ieee80211_hdr *hdr; |
| 859 | struct ath9k_htc_priv *priv = hw->priv; |
Sujith Manoharan | 8e86a54 | 2011-04-13 11:25:29 +0530 | [diff] [blame] | 860 | struct ath_common *common = ath9k_hw_common(priv->ah); |
Sujith Manoharan | 2c5d57f | 2011-04-13 11:25:47 +0530 | [diff] [blame] | 861 | int padpos, padsize, ret, slot; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 862 | |
| 863 | hdr = (struct ieee80211_hdr *) skb->data; |
| 864 | |
| 865 | /* Add the padding after the header if this is not already done */ |
| 866 | padpos = ath9k_cmn_padpos(hdr->frame_control); |
| 867 | padsize = padpos & 3; |
| 868 | if (padsize && skb->len > padpos) { |
Sujith Manoharan | 8e86a54 | 2011-04-13 11:25:29 +0530 | [diff] [blame] | 869 | if (skb_headroom(skb) < padsize) { |
| 870 | ath_dbg(common, ATH_DBG_XMIT, "No room for padding\n"); |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 871 | goto fail_tx; |
Sujith Manoharan | 8e86a54 | 2011-04-13 11:25:29 +0530 | [diff] [blame] | 872 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 873 | skb_push(skb, padsize); |
| 874 | memmove(skb->data, skb->data + padsize, padpos); |
| 875 | } |
| 876 | |
Sujith Manoharan | 2c5d57f | 2011-04-13 11:25:47 +0530 | [diff] [blame] | 877 | slot = ath9k_htc_tx_get_slot(priv); |
| 878 | if (slot < 0) { |
| 879 | ath_dbg(common, ATH_DBG_XMIT, "No free TX slot\n"); |
| 880 | goto fail_tx; |
| 881 | } |
| 882 | |
| 883 | ret = ath9k_htc_tx_start(priv, skb, slot, false); |
Sujith | 7757dfe | 2010-03-29 16:07:17 +0530 | [diff] [blame] | 884 | if (ret != 0) { |
Sujith Manoharan | 8e86a54 | 2011-04-13 11:25:29 +0530 | [diff] [blame] | 885 | ath_dbg(common, ATH_DBG_XMIT, "Tx failed\n"); |
Sujith Manoharan | 2c5d57f | 2011-04-13 11:25:47 +0530 | [diff] [blame] | 886 | goto clear_slot; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 887 | } |
| 888 | |
Sujith Manoharan | 8e86a54 | 2011-04-13 11:25:29 +0530 | [diff] [blame] | 889 | ath9k_htc_check_stop_queues(priv); |
| 890 | |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 891 | return; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 892 | |
Sujith Manoharan | 2c5d57f | 2011-04-13 11:25:47 +0530 | [diff] [blame] | 893 | clear_slot: |
| 894 | ath9k_htc_tx_clear_slot(priv, slot); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 895 | fail_tx: |
| 896 | dev_kfree_skb_any(skb); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 897 | } |
| 898 | |
Sujith | 881ac6a | 2010-06-01 15:14:11 +0530 | [diff] [blame] | 899 | static int ath9k_htc_start(struct ieee80211_hw *hw) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 900 | { |
| 901 | struct ath9k_htc_priv *priv = hw->priv; |
| 902 | struct ath_hw *ah = priv->ah; |
| 903 | struct ath_common *common = ath9k_hw_common(ah); |
| 904 | struct ieee80211_channel *curchan = hw->conf.channel; |
| 905 | struct ath9k_channel *init_channel; |
| 906 | int ret = 0; |
| 907 | enum htc_phymode mode; |
Sujith | 7f1f5a0 | 2010-04-16 11:54:03 +0530 | [diff] [blame] | 908 | __be16 htc_mode; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 909 | u8 cmd_rsp; |
| 910 | |
Sujith | 881ac6a | 2010-06-01 15:14:11 +0530 | [diff] [blame] | 911 | mutex_lock(&priv->mutex); |
| 912 | |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 913 | ath_dbg(common, ATH_DBG_CONFIG, |
| 914 | "Starting driver with initial channel: %d MHz\n", |
| 915 | curchan->center_freq); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 916 | |
Sujith | 21d5130 | 2010-06-01 15:14:18 +0530 | [diff] [blame] | 917 | /* Ensure that HW is awake before flushing RX */ |
| 918 | ath9k_htc_setpower(priv, ATH9K_PM_AWAKE); |
| 919 | WMI_CMD(WMI_FLUSH_RECV_CMDID); |
| 920 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 921 | /* setup initial channel */ |
| 922 | init_channel = ath9k_cmn_get_curchannel(hw, ah); |
| 923 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 924 | ath9k_hw_htc_resetinit(ah); |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 925 | ret = ath9k_hw_reset(ah, init_channel, ah->caldata, false); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 926 | if (ret) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 927 | ath_err(common, |
| 928 | "Unable to reset hardware; reset status %d (freq %u MHz)\n", |
| 929 | ret, curchan->center_freq); |
Sujith | 881ac6a | 2010-06-01 15:14:11 +0530 | [diff] [blame] | 930 | mutex_unlock(&priv->mutex); |
Vivek Natarajan | 8a8572a | 2010-04-27 13:05:37 +0530 | [diff] [blame] | 931 | return ret; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 932 | } |
| 933 | |
Rajkumar Manoharan | b2a5c3d | 2011-01-31 23:47:45 +0530 | [diff] [blame] | 934 | ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit, |
| 935 | &priv->curtxpow); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 936 | |
| 937 | mode = ath9k_htc_get_curmode(priv, init_channel); |
| 938 | htc_mode = cpu_to_be16(mode); |
| 939 | WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 940 | WMI_CMD(WMI_ATH_INIT_CMDID); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 941 | WMI_CMD(WMI_START_RECV_CMDID); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 942 | |
| 943 | ath9k_host_rx_init(priv); |
| 944 | |
Sujith Manoharan | 3a0593e | 2011-04-20 14:33:28 +0530 | [diff] [blame] | 945 | ret = ath9k_htc_update_cap_target(priv, 0); |
Sujith Manoharan | 1057b75 | 2011-02-21 07:48:09 +0530 | [diff] [blame] | 946 | if (ret) |
| 947 | ath_dbg(common, ATH_DBG_CONFIG, |
| 948 | "Failed to update capability in target\n"); |
| 949 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 950 | priv->op_flags &= ~OP_INVALID; |
| 951 | htc_start(priv->htc); |
| 952 | |
Sujith Manoharan | 658ef04 | 2011-04-13 11:25:00 +0530 | [diff] [blame] | 953 | spin_lock_bh(&priv->tx.tx_lock); |
Sujith Manoharan | 8e86a54 | 2011-04-13 11:25:29 +0530 | [diff] [blame] | 954 | priv->tx.flags &= ~ATH9K_HTC_OP_TX_QUEUES_STOP; |
Sujith Manoharan | 658ef04 | 2011-04-13 11:25:00 +0530 | [diff] [blame] | 955 | spin_unlock_bh(&priv->tx.tx_lock); |
Sujith | 7757dfe | 2010-03-29 16:07:17 +0530 | [diff] [blame] | 956 | |
| 957 | ieee80211_wake_queues(hw); |
| 958 | |
Sujith Manoharan | 859c3ca | 2011-04-13 11:26:39 +0530 | [diff] [blame] | 959 | mod_timer(&priv->tx.cleanup_timer, |
| 960 | jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL)); |
| 961 | |
Vivek Natarajan | 21cb987 | 2010-08-18 19:57:49 +0530 | [diff] [blame] | 962 | if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE) { |
| 963 | ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT, |
| 964 | AR_STOMP_LOW_WLAN_WGHT); |
| 965 | ath9k_hw_btcoex_enable(ah); |
| 966 | ath_htc_resume_btcoex_work(priv); |
| 967 | } |
Vivek Natarajan | 8a8572a | 2010-04-27 13:05:37 +0530 | [diff] [blame] | 968 | mutex_unlock(&priv->mutex); |
| 969 | |
| 970 | return ret; |
| 971 | } |
| 972 | |
Sujith | 881ac6a | 2010-06-01 15:14:11 +0530 | [diff] [blame] | 973 | static void ath9k_htc_stop(struct ieee80211_hw *hw) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 974 | { |
| 975 | struct ath9k_htc_priv *priv = hw->priv; |
| 976 | struct ath_hw *ah = priv->ah; |
| 977 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith Manoharan | 0ff2b5c | 2011-04-20 11:00:34 +0530 | [diff] [blame] | 978 | int ret __attribute__ ((unused)); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 979 | u8 cmd_rsp; |
| 980 | |
Sujith | 881ac6a | 2010-06-01 15:14:11 +0530 | [diff] [blame] | 981 | mutex_lock(&priv->mutex); |
| 982 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 983 | if (priv->op_flags & OP_INVALID) { |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 984 | ath_dbg(common, ATH_DBG_ANY, "Device not present\n"); |
Sujith | 881ac6a | 2010-06-01 15:14:11 +0530 | [diff] [blame] | 985 | mutex_unlock(&priv->mutex); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 986 | return; |
| 987 | } |
| 988 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 989 | ath9k_htc_ps_wakeup(priv); |
Sujith Manoharan | b587fc8 | 2011-04-13 11:25:59 +0530 | [diff] [blame] | 990 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 991 | WMI_CMD(WMI_DISABLE_INTR_CMDID); |
| 992 | WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID); |
| 993 | WMI_CMD(WMI_STOP_RECV_CMDID); |
Stanislaw Gruszka | ea88835 | 2011-01-25 14:15:12 +0100 | [diff] [blame] | 994 | |
Stanislaw Gruszka | ea88835 | 2011-01-25 14:15:12 +0100 | [diff] [blame] | 995 | tasklet_kill(&priv->rx_tasklet); |
Stanislaw Gruszka | ea88835 | 2011-01-25 14:15:12 +0100 | [diff] [blame] | 996 | |
Sujith Manoharan | 859c3ca | 2011-04-13 11:26:39 +0530 | [diff] [blame] | 997 | del_timer_sync(&priv->tx.cleanup_timer); |
Sujith Manoharan | b587fc8 | 2011-04-13 11:25:59 +0530 | [diff] [blame] | 998 | ath9k_htc_tx_drain(priv); |
Sujith Manoharan | f4c8899 | 2011-04-13 11:23:52 +0530 | [diff] [blame] | 999 | ath9k_wmi_event_drain(priv); |
| 1000 | |
Stanislaw Gruszka | ea88835 | 2011-01-25 14:15:12 +0100 | [diff] [blame] | 1001 | mutex_unlock(&priv->mutex); |
| 1002 | |
| 1003 | /* Cancel all the running timers/work .. */ |
| 1004 | cancel_work_sync(&priv->fatal_work); |
| 1005 | cancel_work_sync(&priv->ps_work); |
Sujith Manoharan | d244f21 | 2011-04-28 16:14:05 +0530 | [diff] [blame^] | 1006 | |
| 1007 | #ifdef CONFIG_MAC80211_LEDS |
| 1008 | cancel_work_sync(&priv->led_work); |
| 1009 | #endif |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 1010 | ath9k_htc_stop_ani(priv); |
Stanislaw Gruszka | ea88835 | 2011-01-25 14:15:12 +0100 | [diff] [blame] | 1011 | |
| 1012 | mutex_lock(&priv->mutex); |
| 1013 | |
Vivek Natarajan | 21cb987 | 2010-08-18 19:57:49 +0530 | [diff] [blame] | 1014 | if (ah->btcoex_hw.enabled) { |
| 1015 | ath9k_hw_btcoex_disable(ah); |
| 1016 | if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE) |
| 1017 | ath_htc_cancel_btcoex_work(priv); |
| 1018 | } |
| 1019 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 1020 | /* Remove a monitor interface if it's present. */ |
| 1021 | if (priv->ah->is_monitoring) |
| 1022 | ath9k_htc_remove_monitor_interface(priv); |
| 1023 | |
Sujith | e9201f0 | 2010-06-01 15:14:17 +0530 | [diff] [blame] | 1024 | ath9k_hw_phy_disable(ah); |
| 1025 | ath9k_hw_disable(ah); |
Sujith | e9201f0 | 2010-06-01 15:14:17 +0530 | [diff] [blame] | 1026 | ath9k_htc_ps_restore(priv); |
| 1027 | ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP); |
| 1028 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1029 | priv->op_flags |= OP_INVALID; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1030 | |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 1031 | ath_dbg(common, ATH_DBG_CONFIG, "Driver halt\n"); |
Vivek Natarajan | 8a8572a | 2010-04-27 13:05:37 +0530 | [diff] [blame] | 1032 | mutex_unlock(&priv->mutex); |
| 1033 | } |
| 1034 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1035 | static int ath9k_htc_add_interface(struct ieee80211_hw *hw, |
| 1036 | struct ieee80211_vif *vif) |
| 1037 | { |
| 1038 | struct ath9k_htc_priv *priv = hw->priv; |
| 1039 | struct ath9k_htc_vif *avp = (void *)vif->drv_priv; |
| 1040 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 1041 | struct ath9k_htc_target_vif hvif; |
| 1042 | int ret = 0; |
| 1043 | u8 cmd_rsp; |
| 1044 | |
| 1045 | mutex_lock(&priv->mutex); |
| 1046 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 1047 | if (priv->nvifs >= ATH9K_HTC_MAX_VIF) { |
Sujith Manoharan | ab77c70 | 2011-02-21 07:48:16 +0530 | [diff] [blame] | 1048 | mutex_unlock(&priv->mutex); |
Sujith Manoharan | 0df8359 | 2011-02-21 07:49:15 +0530 | [diff] [blame] | 1049 | return -ENOBUFS; |
| 1050 | } |
| 1051 | |
| 1052 | if (priv->num_ibss_vif || |
| 1053 | (priv->nvifs && vif->type == NL80211_IFTYPE_ADHOC)) { |
| 1054 | ath_err(common, "IBSS coexistence with other modes is not allowed\n"); |
| 1055 | mutex_unlock(&priv->mutex); |
| 1056 | return -ENOBUFS; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1057 | } |
| 1058 | |
Sujith Manoharan | da8d9d9 | 2011-02-21 07:49:23 +0530 | [diff] [blame] | 1059 | if (((vif->type == NL80211_IFTYPE_AP) || |
| 1060 | (vif->type == NL80211_IFTYPE_ADHOC)) && |
| 1061 | ((priv->num_ap_vif + priv->num_ibss_vif) >= ATH9K_HTC_MAX_BCN_VIF)) { |
| 1062 | ath_err(common, "Max. number of beaconing interfaces reached\n"); |
| 1063 | mutex_unlock(&priv->mutex); |
| 1064 | return -ENOBUFS; |
| 1065 | } |
| 1066 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1067 | ath9k_htc_ps_wakeup(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1068 | memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif)); |
| 1069 | memcpy(&hvif.myaddr, vif->addr, ETH_ALEN); |
| 1070 | |
| 1071 | switch (vif->type) { |
| 1072 | case NL80211_IFTYPE_STATION: |
Sujith Manoharan | e4c6250 | 2011-04-13 11:24:43 +0530 | [diff] [blame] | 1073 | hvif.opmode = HTC_M_STA; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1074 | break; |
| 1075 | case NL80211_IFTYPE_ADHOC: |
Sujith Manoharan | e4c6250 | 2011-04-13 11:24:43 +0530 | [diff] [blame] | 1076 | hvif.opmode = HTC_M_IBSS; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1077 | break; |
Sujith Manoharan | da8d9d9 | 2011-02-21 07:49:23 +0530 | [diff] [blame] | 1078 | case NL80211_IFTYPE_AP: |
Sujith Manoharan | e4c6250 | 2011-04-13 11:24:43 +0530 | [diff] [blame] | 1079 | hvif.opmode = HTC_M_HOSTAP; |
Sujith Manoharan | da8d9d9 | 2011-02-21 07:49:23 +0530 | [diff] [blame] | 1080 | break; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1081 | default: |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 1082 | ath_err(common, |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1083 | "Interface type %d not yet supported\n", vif->type); |
| 1084 | ret = -EOPNOTSUPP; |
| 1085 | goto out; |
| 1086 | } |
| 1087 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1088 | /* Index starts from zero on the target */ |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 1089 | avp->index = hvif.index = ffz(priv->vif_slot); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1090 | hvif.rtsthreshold = cpu_to_be16(2304); |
| 1091 | WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif); |
| 1092 | if (ret) |
| 1093 | goto out; |
| 1094 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1095 | /* |
| 1096 | * We need a node in target to tx mgmt frames |
| 1097 | * before association. |
| 1098 | */ |
| 1099 | ret = ath9k_htc_add_station(priv, vif, NULL); |
Sujith Manoharan | ab77c70 | 2011-02-21 07:48:16 +0530 | [diff] [blame] | 1100 | if (ret) { |
| 1101 | WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1102 | goto out; |
Sujith Manoharan | ab77c70 | 2011-02-21 07:48:16 +0530 | [diff] [blame] | 1103 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1104 | |
Sujith Manoharan | 585895c | 2011-02-21 07:48:46 +0530 | [diff] [blame] | 1105 | ath9k_htc_set_bssid_mask(priv, vif); |
| 1106 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 1107 | priv->vif_slot |= (1 << avp->index); |
Sujith Manoharan | ab77c70 | 2011-02-21 07:48:16 +0530 | [diff] [blame] | 1108 | priv->nvifs++; |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 1109 | |
Sujith Manoharan | 0df8359 | 2011-02-21 07:49:15 +0530 | [diff] [blame] | 1110 | INC_VIF(priv, vif->type); |
Sujith Manoharan | 832f6a1 | 2011-04-13 11:23:08 +0530 | [diff] [blame] | 1111 | |
| 1112 | if ((vif->type == NL80211_IFTYPE_AP) || |
| 1113 | (vif->type == NL80211_IFTYPE_ADHOC)) |
| 1114 | ath9k_htc_assign_bslot(priv, vif); |
| 1115 | |
Sujith Manoharan | ffbe7c8 | 2011-02-21 07:49:31 +0530 | [diff] [blame] | 1116 | ath9k_htc_set_opmode(priv); |
Sujith Manoharan | 0df8359 | 2011-02-21 07:49:15 +0530 | [diff] [blame] | 1117 | |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 1118 | if ((priv->ah->opmode == NL80211_IFTYPE_AP) && |
Sujith Manoharan | 9b674a0 | 2011-04-13 11:23:17 +0530 | [diff] [blame] | 1119 | !(priv->op_flags & OP_ANI_RUNNING)) { |
| 1120 | ath9k_hw_set_tsfadjust(priv->ah, 1); |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 1121 | ath9k_htc_start_ani(priv); |
Sujith Manoharan | 9b674a0 | 2011-04-13 11:23:17 +0530 | [diff] [blame] | 1122 | } |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 1123 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 1124 | ath_dbg(common, ATH_DBG_CONFIG, |
| 1125 | "Attach a VIF of type: %d at idx: %d\n", vif->type, avp->index); |
| 1126 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1127 | out: |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1128 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1129 | mutex_unlock(&priv->mutex); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1130 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1131 | return ret; |
| 1132 | } |
| 1133 | |
| 1134 | static void ath9k_htc_remove_interface(struct ieee80211_hw *hw, |
| 1135 | struct ieee80211_vif *vif) |
| 1136 | { |
| 1137 | struct ath9k_htc_priv *priv = hw->priv; |
| 1138 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 1139 | struct ath9k_htc_vif *avp = (void *)vif->drv_priv; |
| 1140 | struct ath9k_htc_target_vif hvif; |
| 1141 | int ret = 0; |
| 1142 | u8 cmd_rsp; |
| 1143 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1144 | mutex_lock(&priv->mutex); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1145 | ath9k_htc_ps_wakeup(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1146 | |
| 1147 | memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif)); |
| 1148 | memcpy(&hvif.myaddr, vif->addr, ETH_ALEN); |
| 1149 | hvif.index = avp->index; |
| 1150 | WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif); |
Sujith Manoharan | 0ff2b5c | 2011-04-20 11:00:34 +0530 | [diff] [blame] | 1151 | if (ret) { |
| 1152 | ath_err(common, "Unable to remove interface at idx: %d\n", |
| 1153 | avp->index); |
| 1154 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1155 | priv->nvifs--; |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 1156 | priv->vif_slot &= ~(1 << avp->index); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1157 | |
| 1158 | ath9k_htc_remove_station(priv, vif, NULL); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1159 | |
Sujith Manoharan | 0df8359 | 2011-02-21 07:49:15 +0530 | [diff] [blame] | 1160 | DEC_VIF(priv, vif->type); |
Sujith Manoharan | 832f6a1 | 2011-04-13 11:23:08 +0530 | [diff] [blame] | 1161 | |
| 1162 | if ((vif->type == NL80211_IFTYPE_AP) || |
| 1163 | (vif->type == NL80211_IFTYPE_ADHOC)) |
| 1164 | ath9k_htc_remove_bslot(priv, vif); |
| 1165 | |
Sujith Manoharan | ffbe7c8 | 2011-02-21 07:49:31 +0530 | [diff] [blame] | 1166 | ath9k_htc_set_opmode(priv); |
Sujith Manoharan | 0df8359 | 2011-02-21 07:49:15 +0530 | [diff] [blame] | 1167 | |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 1168 | /* |
| 1169 | * Stop ANI only if there are no associated station interfaces. |
| 1170 | */ |
| 1171 | if ((vif->type == NL80211_IFTYPE_AP) && (priv->num_ap_vif == 0)) { |
| 1172 | priv->rearm_ani = false; |
| 1173 | ieee80211_iterate_active_interfaces_atomic(priv->hw, |
| 1174 | ath9k_htc_vif_iter, priv); |
| 1175 | if (!priv->rearm_ani) |
| 1176 | ath9k_htc_stop_ani(priv); |
| 1177 | } |
| 1178 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 1179 | ath_dbg(common, ATH_DBG_CONFIG, "Detach Interface at idx: %d\n", avp->index); |
| 1180 | |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1181 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1182 | mutex_unlock(&priv->mutex); |
| 1183 | } |
| 1184 | |
| 1185 | static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed) |
| 1186 | { |
| 1187 | struct ath9k_htc_priv *priv = hw->priv; |
| 1188 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 1189 | struct ieee80211_conf *conf = &hw->conf; |
| 1190 | |
| 1191 | mutex_lock(&priv->mutex); |
| 1192 | |
Vivek Natarajan | 8a8572a | 2010-04-27 13:05:37 +0530 | [diff] [blame] | 1193 | if (changed & IEEE80211_CONF_CHANGE_IDLE) { |
| 1194 | bool enable_radio = false; |
| 1195 | bool idle = !!(conf->flags & IEEE80211_CONF_IDLE); |
| 1196 | |
Sujith | 2336776 | 2010-06-01 15:14:16 +0530 | [diff] [blame] | 1197 | mutex_lock(&priv->htc_pm_lock); |
Vivek Natarajan | 8a8572a | 2010-04-27 13:05:37 +0530 | [diff] [blame] | 1198 | if (!idle && priv->ps_idle) |
| 1199 | enable_radio = true; |
Vivek Natarajan | 8a8572a | 2010-04-27 13:05:37 +0530 | [diff] [blame] | 1200 | priv->ps_idle = idle; |
Sujith | 2336776 | 2010-06-01 15:14:16 +0530 | [diff] [blame] | 1201 | mutex_unlock(&priv->htc_pm_lock); |
Vivek Natarajan | 8a8572a | 2010-04-27 13:05:37 +0530 | [diff] [blame] | 1202 | |
| 1203 | if (enable_radio) { |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 1204 | ath_dbg(common, ATH_DBG_CONFIG, |
| 1205 | "not-idle: enabling radio\n"); |
Sujith | 2336776 | 2010-06-01 15:14:16 +0530 | [diff] [blame] | 1206 | ath9k_htc_setpower(priv, ATH9K_PM_AWAKE); |
| 1207 | ath9k_htc_radio_enable(hw); |
Vivek Natarajan | 8a8572a | 2010-04-27 13:05:37 +0530 | [diff] [blame] | 1208 | } |
| 1209 | } |
| 1210 | |
Sujith Manoharan | 55de80d | 2011-01-05 01:06:21 +0530 | [diff] [blame] | 1211 | /* |
| 1212 | * Monitor interface should be added before |
| 1213 | * IEEE80211_CONF_CHANGE_CHANNEL is handled. |
| 1214 | */ |
| 1215 | if (changed & IEEE80211_CONF_CHANGE_MONITOR) { |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 1216 | if ((conf->flags & IEEE80211_CONF_MONITOR) && |
| 1217 | !priv->ah->is_monitoring) |
| 1218 | ath9k_htc_add_monitor_interface(priv); |
| 1219 | else if (priv->ah->is_monitoring) |
| 1220 | ath9k_htc_remove_monitor_interface(priv); |
Sujith Manoharan | 55de80d | 2011-01-05 01:06:21 +0530 | [diff] [blame] | 1221 | } |
| 1222 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1223 | if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { |
| 1224 | struct ieee80211_channel *curchan = hw->conf.channel; |
| 1225 | int pos = curchan->hw_value; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1226 | |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 1227 | ath_dbg(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n", |
| 1228 | curchan->center_freq); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1229 | |
Felix Fietkau | babcbc2 | 2010-10-20 02:09:46 +0200 | [diff] [blame] | 1230 | ath9k_cmn_update_ichannel(&priv->ah->channels[pos], |
| 1231 | hw->conf.channel, |
| 1232 | hw->conf.channel_type); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1233 | |
| 1234 | if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 1235 | ath_err(common, "Unable to set channel\n"); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1236 | mutex_unlock(&priv->mutex); |
| 1237 | return -EINVAL; |
| 1238 | } |
| 1239 | |
| 1240 | } |
Sujith Manoharan | 692d6b1 | 2010-12-07 16:31:54 +0530 | [diff] [blame] | 1241 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1242 | if (changed & IEEE80211_CONF_CHANGE_PS) { |
| 1243 | if (conf->flags & IEEE80211_CONF_PS) { |
| 1244 | ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP); |
| 1245 | priv->ps_enabled = true; |
| 1246 | } else { |
| 1247 | priv->ps_enabled = false; |
| 1248 | cancel_work_sync(&priv->ps_work); |
| 1249 | ath9k_htc_setpower(priv, ATH9K_PM_AWAKE); |
| 1250 | } |
| 1251 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1252 | |
Sujith Manoharan | 692d6b1 | 2010-12-07 16:31:54 +0530 | [diff] [blame] | 1253 | if (changed & IEEE80211_CONF_CHANGE_POWER) { |
| 1254 | priv->txpowlimit = 2 * conf->power_level; |
Rajkumar Manoharan | b2a5c3d | 2011-01-31 23:47:45 +0530 | [diff] [blame] | 1255 | ath9k_cmn_update_txpow(priv->ah, priv->curtxpow, |
| 1256 | priv->txpowlimit, &priv->curtxpow); |
Sujith Manoharan | 692d6b1 | 2010-12-07 16:31:54 +0530 | [diff] [blame] | 1257 | } |
| 1258 | |
Sujith | 2336776 | 2010-06-01 15:14:16 +0530 | [diff] [blame] | 1259 | if (changed & IEEE80211_CONF_CHANGE_IDLE) { |
| 1260 | mutex_lock(&priv->htc_pm_lock); |
| 1261 | if (!priv->ps_idle) { |
| 1262 | mutex_unlock(&priv->htc_pm_lock); |
| 1263 | goto out; |
| 1264 | } |
| 1265 | mutex_unlock(&priv->htc_pm_lock); |
| 1266 | |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 1267 | ath_dbg(common, ATH_DBG_CONFIG, |
| 1268 | "idle: disabling radio\n"); |
Sujith | 881ac6a | 2010-06-01 15:14:11 +0530 | [diff] [blame] | 1269 | ath9k_htc_radio_disable(hw); |
Vivek Natarajan | 8a8572a | 2010-04-27 13:05:37 +0530 | [diff] [blame] | 1270 | } |
| 1271 | |
Sujith | 2336776 | 2010-06-01 15:14:16 +0530 | [diff] [blame] | 1272 | out: |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1273 | mutex_unlock(&priv->mutex); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1274 | return 0; |
| 1275 | } |
| 1276 | |
| 1277 | #define SUPPORTED_FILTERS \ |
| 1278 | (FIF_PROMISC_IN_BSS | \ |
| 1279 | FIF_ALLMULTI | \ |
| 1280 | FIF_CONTROL | \ |
| 1281 | FIF_PSPOLL | \ |
| 1282 | FIF_OTHER_BSS | \ |
| 1283 | FIF_BCN_PRBRESP_PROMISC | \ |
Rajkumar Manoharan | 94a40c0 | 2010-10-14 10:50:26 +0530 | [diff] [blame] | 1284 | FIF_PROBE_REQ | \ |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1285 | FIF_FCSFAIL) |
| 1286 | |
| 1287 | static void ath9k_htc_configure_filter(struct ieee80211_hw *hw, |
| 1288 | unsigned int changed_flags, |
| 1289 | unsigned int *total_flags, |
| 1290 | u64 multicast) |
| 1291 | { |
| 1292 | struct ath9k_htc_priv *priv = hw->priv; |
| 1293 | u32 rfilt; |
| 1294 | |
| 1295 | mutex_lock(&priv->mutex); |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1296 | ath9k_htc_ps_wakeup(priv); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1297 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1298 | changed_flags &= SUPPORTED_FILTERS; |
| 1299 | *total_flags &= SUPPORTED_FILTERS; |
| 1300 | |
| 1301 | priv->rxfilter = *total_flags; |
Sujith | 0995d11 | 2010-03-29 16:07:09 +0530 | [diff] [blame] | 1302 | rfilt = ath9k_htc_calcrxfilter(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1303 | ath9k_hw_setrxfilter(priv->ah, rfilt); |
| 1304 | |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 1305 | ath_dbg(ath9k_hw_common(priv->ah), ATH_DBG_CONFIG, |
| 1306 | "Set HW RX filter: 0x%x\n", rfilt); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1307 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1308 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1309 | mutex_unlock(&priv->mutex); |
| 1310 | } |
| 1311 | |
Sujith | abd984e | 2010-05-18 15:26:04 +0530 | [diff] [blame] | 1312 | static int ath9k_htc_sta_add(struct ieee80211_hw *hw, |
| 1313 | struct ieee80211_vif *vif, |
| 1314 | struct ieee80211_sta *sta) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1315 | { |
| 1316 | struct ath9k_htc_priv *priv = hw->priv; |
| 1317 | int ret; |
| 1318 | |
Sujith.Manoharan@atheros.com | 05a30f9 | 2010-05-11 16:24:38 +0530 | [diff] [blame] | 1319 | mutex_lock(&priv->mutex); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1320 | ath9k_htc_ps_wakeup(priv); |
Sujith | abd984e | 2010-05-18 15:26:04 +0530 | [diff] [blame] | 1321 | ret = ath9k_htc_add_station(priv, vif, sta); |
| 1322 | if (!ret) |
| 1323 | ath9k_htc_init_rate(priv, sta); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1324 | ath9k_htc_ps_restore(priv); |
Sujith.Manoharan@atheros.com | 05a30f9 | 2010-05-11 16:24:38 +0530 | [diff] [blame] | 1325 | mutex_unlock(&priv->mutex); |
Sujith | abd984e | 2010-05-18 15:26:04 +0530 | [diff] [blame] | 1326 | |
| 1327 | return ret; |
| 1328 | } |
| 1329 | |
| 1330 | static int ath9k_htc_sta_remove(struct ieee80211_hw *hw, |
| 1331 | struct ieee80211_vif *vif, |
| 1332 | struct ieee80211_sta *sta) |
| 1333 | { |
| 1334 | struct ath9k_htc_priv *priv = hw->priv; |
Sujith Manoharan | 84c9e164 | 2011-04-13 11:26:11 +0530 | [diff] [blame] | 1335 | struct ath9k_htc_sta *ista; |
Sujith | abd984e | 2010-05-18 15:26:04 +0530 | [diff] [blame] | 1336 | int ret; |
| 1337 | |
| 1338 | mutex_lock(&priv->mutex); |
| 1339 | ath9k_htc_ps_wakeup(priv); |
Sujith Manoharan | 84c9e164 | 2011-04-13 11:26:11 +0530 | [diff] [blame] | 1340 | ista = (struct ath9k_htc_sta *) sta->drv_priv; |
| 1341 | htc_sta_drain(priv->htc, ista->index); |
Sujith | abd984e | 2010-05-18 15:26:04 +0530 | [diff] [blame] | 1342 | ret = ath9k_htc_remove_station(priv, vif, sta); |
| 1343 | ath9k_htc_ps_restore(priv); |
| 1344 | mutex_unlock(&priv->mutex); |
| 1345 | |
| 1346 | return ret; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1347 | } |
| 1348 | |
| 1349 | static int ath9k_htc_conf_tx(struct ieee80211_hw *hw, u16 queue, |
| 1350 | const struct ieee80211_tx_queue_params *params) |
| 1351 | { |
| 1352 | struct ath9k_htc_priv *priv = hw->priv; |
| 1353 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 1354 | struct ath9k_tx_queue_info qi; |
| 1355 | int ret = 0, qnum; |
| 1356 | |
| 1357 | if (queue >= WME_NUM_AC) |
| 1358 | return 0; |
| 1359 | |
| 1360 | mutex_lock(&priv->mutex); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1361 | ath9k_htc_ps_wakeup(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1362 | |
| 1363 | memset(&qi, 0, sizeof(struct ath9k_tx_queue_info)); |
| 1364 | |
| 1365 | qi.tqi_aifs = params->aifs; |
| 1366 | qi.tqi_cwmin = params->cw_min; |
| 1367 | qi.tqi_cwmax = params->cw_max; |
| 1368 | qi.tqi_burstTime = params->txop; |
| 1369 | |
| 1370 | qnum = get_hw_qnum(queue, priv->hwq_map); |
| 1371 | |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 1372 | ath_dbg(common, ATH_DBG_CONFIG, |
| 1373 | "Configure tx [queue/hwq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n", |
| 1374 | queue, qnum, params->aifs, params->cw_min, |
| 1375 | params->cw_max, params->txop); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1376 | |
Sujith | e1572c5 | 2010-03-24 13:42:13 +0530 | [diff] [blame] | 1377 | ret = ath_htc_txq_update(priv, qnum, &qi); |
Sujith | 764580f | 2010-06-01 15:14:19 +0530 | [diff] [blame] | 1378 | if (ret) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 1379 | ath_err(common, "TXQ Update failed\n"); |
Sujith | 764580f | 2010-06-01 15:14:19 +0530 | [diff] [blame] | 1380 | goto out; |
| 1381 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1382 | |
Sujith | 764580f | 2010-06-01 15:14:19 +0530 | [diff] [blame] | 1383 | if ((priv->ah->opmode == NL80211_IFTYPE_ADHOC) && |
Felix Fietkau | e8c35a7 | 2010-06-12 00:33:50 -0400 | [diff] [blame] | 1384 | (qnum == priv->hwq_map[WME_AC_BE])) |
Sujith | 764580f | 2010-06-01 15:14:19 +0530 | [diff] [blame] | 1385 | ath9k_htc_beaconq_config(priv); |
| 1386 | out: |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1387 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1388 | mutex_unlock(&priv->mutex); |
| 1389 | |
| 1390 | return ret; |
| 1391 | } |
| 1392 | |
| 1393 | static int ath9k_htc_set_key(struct ieee80211_hw *hw, |
| 1394 | enum set_key_cmd cmd, |
| 1395 | struct ieee80211_vif *vif, |
| 1396 | struct ieee80211_sta *sta, |
| 1397 | struct ieee80211_key_conf *key) |
| 1398 | { |
| 1399 | struct ath9k_htc_priv *priv = hw->priv; |
| 1400 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 1401 | int ret = 0; |
| 1402 | |
Sujith | e1572c5 | 2010-03-24 13:42:13 +0530 | [diff] [blame] | 1403 | if (htc_modparam_nohwcrypt) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1404 | return -ENOSPC; |
| 1405 | |
| 1406 | mutex_lock(&priv->mutex); |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 1407 | ath_dbg(common, ATH_DBG_CONFIG, "Set HW Key\n"); |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1408 | ath9k_htc_ps_wakeup(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1409 | |
| 1410 | switch (cmd) { |
| 1411 | case SET_KEY: |
Bruno Randolf | 040e539 | 2010-09-08 16:05:04 +0900 | [diff] [blame] | 1412 | ret = ath_key_config(common, vif, sta, key); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1413 | if (ret >= 0) { |
| 1414 | key->hw_key_idx = ret; |
| 1415 | /* push IV and Michael MIC generation to stack */ |
| 1416 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 1417 | if (key->cipher == WLAN_CIPHER_SUITE_TKIP) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1418 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 1419 | if (priv->ah->sw_mgmt_crypto && |
| 1420 | key->cipher == WLAN_CIPHER_SUITE_CCMP) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1421 | key->flags |= IEEE80211_KEY_FLAG_SW_MGMT; |
| 1422 | ret = 0; |
| 1423 | } |
| 1424 | break; |
| 1425 | case DISABLE_KEY: |
Bruno Randolf | 040e539 | 2010-09-08 16:05:04 +0900 | [diff] [blame] | 1426 | ath_key_delete(common, key); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1427 | break; |
| 1428 | default: |
| 1429 | ret = -EINVAL; |
| 1430 | } |
| 1431 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1432 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1433 | mutex_unlock(&priv->mutex); |
| 1434 | |
| 1435 | return ret; |
| 1436 | } |
| 1437 | |
| 1438 | static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw, |
| 1439 | struct ieee80211_vif *vif, |
| 1440 | struct ieee80211_bss_conf *bss_conf, |
| 1441 | u32 changed) |
| 1442 | { |
| 1443 | struct ath9k_htc_priv *priv = hw->priv; |
| 1444 | struct ath_hw *ah = priv->ah; |
| 1445 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith Manoharan | e7a2a4f | 2011-02-27 09:20:40 +0530 | [diff] [blame] | 1446 | bool set_assoc; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1447 | |
| 1448 | mutex_lock(&priv->mutex); |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1449 | ath9k_htc_ps_wakeup(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1450 | |
Sujith Manoharan | e7a2a4f | 2011-02-27 09:20:40 +0530 | [diff] [blame] | 1451 | /* |
| 1452 | * Set the HW AID/BSSID only for the first station interface |
| 1453 | * or in IBSS mode. |
| 1454 | */ |
| 1455 | set_assoc = !!((priv->ah->opmode == NL80211_IFTYPE_ADHOC) || |
| 1456 | ((priv->ah->opmode == NL80211_IFTYPE_STATION) && |
| 1457 | (priv->num_sta_vif == 1))); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1458 | |
Sujith Manoharan | e7a2a4f | 2011-02-27 09:20:40 +0530 | [diff] [blame] | 1459 | |
| 1460 | if (changed & BSS_CHANGED_ASSOC) { |
| 1461 | if (set_assoc) { |
| 1462 | ath_dbg(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n", |
| 1463 | bss_conf->assoc); |
| 1464 | |
| 1465 | common->curaid = bss_conf->assoc ? |
| 1466 | bss_conf->aid : 0; |
| 1467 | |
| 1468 | if (bss_conf->assoc) |
| 1469 | ath9k_htc_start_ani(priv); |
| 1470 | else |
| 1471 | ath9k_htc_stop_ani(priv); |
| 1472 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1473 | } |
| 1474 | |
| 1475 | if (changed & BSS_CHANGED_BSSID) { |
Sujith Manoharan | e7a2a4f | 2011-02-27 09:20:40 +0530 | [diff] [blame] | 1476 | if (set_assoc) { |
| 1477 | memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN); |
| 1478 | ath9k_hw_write_associd(ah); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1479 | |
Sujith Manoharan | e7a2a4f | 2011-02-27 09:20:40 +0530 | [diff] [blame] | 1480 | ath_dbg(common, ATH_DBG_CONFIG, |
| 1481 | "BSSID: %pM aid: 0x%x\n", |
| 1482 | common->curbssid, common->curaid); |
| 1483 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1484 | } |
| 1485 | |
Sujith Manoharan | a5fae37 | 2011-02-21 07:49:53 +0530 | [diff] [blame] | 1486 | if ((changed & BSS_CHANGED_BEACON_ENABLED) && bss_conf->enable_beacon) { |
| 1487 | ath_dbg(common, ATH_DBG_CONFIG, |
| 1488 | "Beacon enabled for BSS: %pM\n", bss_conf->bssid); |
Sujith Manoharan | 9b674a0 | 2011-04-13 11:23:17 +0530 | [diff] [blame] | 1489 | ath9k_htc_set_tsfadjust(priv, vif); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1490 | priv->op_flags |= OP_ENABLE_BEACON; |
Vivek Natarajan | 1c3652a | 2010-04-05 14:48:06 +0530 | [diff] [blame] | 1491 | ath9k_htc_beacon_config(priv, vif); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1492 | } |
| 1493 | |
Sujith Manoharan | a5fae37 | 2011-02-21 07:49:53 +0530 | [diff] [blame] | 1494 | if ((changed & BSS_CHANGED_BEACON_ENABLED) && !bss_conf->enable_beacon) { |
| 1495 | /* |
| 1496 | * Disable SWBA interrupt only if there are no |
| 1497 | * AP/IBSS interfaces. |
| 1498 | */ |
| 1499 | if ((priv->num_ap_vif <= 1) || priv->num_ibss_vif) { |
| 1500 | ath_dbg(common, ATH_DBG_CONFIG, |
| 1501 | "Beacon disabled for BSS: %pM\n", |
| 1502 | bss_conf->bssid); |
| 1503 | priv->op_flags &= ~OP_ENABLE_BEACON; |
| 1504 | ath9k_htc_beacon_config(priv, vif); |
| 1505 | } |
| 1506 | } |
| 1507 | |
| 1508 | if (changed & BSS_CHANGED_BEACON_INT) { |
| 1509 | /* |
| 1510 | * Reset the HW TSF for the first AP interface. |
| 1511 | */ |
| 1512 | if ((priv->ah->opmode == NL80211_IFTYPE_AP) && |
| 1513 | (priv->nvifs == 1) && |
| 1514 | (priv->num_ap_vif == 1) && |
| 1515 | (vif->type == NL80211_IFTYPE_AP)) { |
| 1516 | priv->op_flags |= OP_TSF_RESET; |
| 1517 | } |
| 1518 | ath_dbg(common, ATH_DBG_CONFIG, |
| 1519 | "Beacon interval changed for BSS: %pM\n", |
| 1520 | bss_conf->bssid); |
Vivek Natarajan | 1c3652a | 2010-04-05 14:48:06 +0530 | [diff] [blame] | 1521 | ath9k_htc_beacon_config(priv, vif); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1522 | } |
| 1523 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1524 | if (changed & BSS_CHANGED_ERP_SLOT) { |
| 1525 | if (bss_conf->use_short_slot) |
| 1526 | ah->slottime = 9; |
| 1527 | else |
| 1528 | ah->slottime = 20; |
| 1529 | |
| 1530 | ath9k_hw_init_global_settings(ah); |
| 1531 | } |
| 1532 | |
Sujith | 2c76ef8 | 2010-05-17 12:01:18 +0530 | [diff] [blame] | 1533 | if (changed & BSS_CHANGED_HT) |
| 1534 | ath9k_htc_update_rate(priv, vif, bss_conf); |
| 1535 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1536 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1537 | mutex_unlock(&priv->mutex); |
| 1538 | } |
| 1539 | |
| 1540 | static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw) |
| 1541 | { |
| 1542 | struct ath9k_htc_priv *priv = hw->priv; |
| 1543 | u64 tsf; |
| 1544 | |
| 1545 | mutex_lock(&priv->mutex); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1546 | ath9k_htc_ps_wakeup(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1547 | tsf = ath9k_hw_gettsf64(priv->ah); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1548 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1549 | mutex_unlock(&priv->mutex); |
| 1550 | |
| 1551 | return tsf; |
| 1552 | } |
| 1553 | |
| 1554 | static void ath9k_htc_set_tsf(struct ieee80211_hw *hw, u64 tsf) |
| 1555 | { |
| 1556 | struct ath9k_htc_priv *priv = hw->priv; |
| 1557 | |
| 1558 | mutex_lock(&priv->mutex); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1559 | ath9k_htc_ps_wakeup(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1560 | ath9k_hw_settsf64(priv->ah, tsf); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1561 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1562 | mutex_unlock(&priv->mutex); |
| 1563 | } |
| 1564 | |
| 1565 | static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw) |
| 1566 | { |
| 1567 | struct ath9k_htc_priv *priv = hw->priv; |
| 1568 | |
| 1569 | mutex_lock(&priv->mutex); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1570 | ath9k_htc_ps_wakeup(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1571 | ath9k_hw_reset_tsf(priv->ah); |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1572 | ath9k_htc_ps_restore(priv); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1573 | mutex_unlock(&priv->mutex); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1574 | } |
| 1575 | |
| 1576 | static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw, |
| 1577 | struct ieee80211_vif *vif, |
| 1578 | enum ieee80211_ampdu_mlme_action action, |
| 1579 | struct ieee80211_sta *sta, |
Johannes Berg | 0b01f03 | 2011-01-18 13:51:05 +0100 | [diff] [blame] | 1580 | u16 tid, u16 *ssn, u8 buf_size) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1581 | { |
| 1582 | struct ath9k_htc_priv *priv = hw->priv; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1583 | struct ath9k_htc_sta *ista; |
Sujith | d7ca213 | 2010-06-15 10:24:37 +0530 | [diff] [blame] | 1584 | int ret = 0; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1585 | |
Sujith Manoharan | 87df895 | 2011-02-21 07:49:08 +0530 | [diff] [blame] | 1586 | mutex_lock(&priv->mutex); |
Sujith Manoharan | c58ca5b | 2011-04-20 11:01:10 +0530 | [diff] [blame] | 1587 | ath9k_htc_ps_wakeup(priv); |
Sujith Manoharan | 87df895 | 2011-02-21 07:49:08 +0530 | [diff] [blame] | 1588 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1589 | switch (action) { |
| 1590 | case IEEE80211_AMPDU_RX_START: |
| 1591 | break; |
| 1592 | case IEEE80211_AMPDU_RX_STOP: |
| 1593 | break; |
| 1594 | case IEEE80211_AMPDU_TX_START: |
Sujith | d7ca213 | 2010-06-15 10:24:37 +0530 | [diff] [blame] | 1595 | ret = ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid); |
| 1596 | if (!ret) |
| 1597 | ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 1598 | break; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1599 | case IEEE80211_AMPDU_TX_STOP: |
Sujith | d7ca213 | 2010-06-15 10:24:37 +0530 | [diff] [blame] | 1600 | ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid); |
| 1601 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1602 | break; |
| 1603 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
| 1604 | ista = (struct ath9k_htc_sta *) sta->drv_priv; |
Sujith Manoharan | 658ef04 | 2011-04-13 11:25:00 +0530 | [diff] [blame] | 1605 | spin_lock_bh(&priv->tx.tx_lock); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1606 | ista->tid_state[tid] = AGGR_OPERATIONAL; |
Sujith Manoharan | 658ef04 | 2011-04-13 11:25:00 +0530 | [diff] [blame] | 1607 | spin_unlock_bh(&priv->tx.tx_lock); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1608 | break; |
| 1609 | default: |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 1610 | ath_err(ath9k_hw_common(priv->ah), "Unknown AMPDU action\n"); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1611 | } |
| 1612 | |
Sujith Manoharan | c58ca5b | 2011-04-20 11:01:10 +0530 | [diff] [blame] | 1613 | ath9k_htc_ps_restore(priv); |
Sujith Manoharan | 87df895 | 2011-02-21 07:49:08 +0530 | [diff] [blame] | 1614 | mutex_unlock(&priv->mutex); |
| 1615 | |
Sujith | d7ca213 | 2010-06-15 10:24:37 +0530 | [diff] [blame] | 1616 | return ret; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1617 | } |
| 1618 | |
| 1619 | static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw) |
| 1620 | { |
| 1621 | struct ath9k_htc_priv *priv = hw->priv; |
| 1622 | |
| 1623 | mutex_lock(&priv->mutex); |
| 1624 | spin_lock_bh(&priv->beacon_lock); |
| 1625 | priv->op_flags |= OP_SCANNING; |
| 1626 | spin_unlock_bh(&priv->beacon_lock); |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1627 | cancel_work_sync(&priv->ps_work); |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 1628 | ath9k_htc_stop_ani(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1629 | mutex_unlock(&priv->mutex); |
| 1630 | } |
| 1631 | |
| 1632 | static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw) |
| 1633 | { |
| 1634 | struct ath9k_htc_priv *priv = hw->priv; |
| 1635 | |
| 1636 | mutex_lock(&priv->mutex); |
| 1637 | spin_lock_bh(&priv->beacon_lock); |
| 1638 | priv->op_flags &= ~OP_SCANNING; |
| 1639 | spin_unlock_bh(&priv->beacon_lock); |
Sujith Manoharan | 7c27734 | 2011-02-21 07:48:39 +0530 | [diff] [blame] | 1640 | ath9k_htc_ps_wakeup(priv); |
| 1641 | ath9k_htc_vif_reconfig(priv); |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1642 | ath9k_htc_ps_restore(priv); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1643 | mutex_unlock(&priv->mutex); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1644 | } |
| 1645 | |
| 1646 | static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value) |
| 1647 | { |
| 1648 | return 0; |
| 1649 | } |
| 1650 | |
| 1651 | static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw, |
| 1652 | u8 coverage_class) |
| 1653 | { |
| 1654 | struct ath9k_htc_priv *priv = hw->priv; |
| 1655 | |
| 1656 | mutex_lock(&priv->mutex); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1657 | ath9k_htc_ps_wakeup(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1658 | priv->ah->coverage_class = coverage_class; |
| 1659 | ath9k_hw_init_global_settings(priv->ah); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1660 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1661 | mutex_unlock(&priv->mutex); |
| 1662 | } |
| 1663 | |
Sujith Manoharan | e2186b7 | 2011-04-27 17:13:40 +0530 | [diff] [blame] | 1664 | /* |
| 1665 | * Currently, this is used only for selecting the minimum rate |
| 1666 | * for management frames, rate selection for data frames remain |
| 1667 | * unaffected. |
| 1668 | */ |
| 1669 | static int ath9k_htc_set_bitrate_mask(struct ieee80211_hw *hw, |
| 1670 | struct ieee80211_vif *vif, |
| 1671 | const struct cfg80211_bitrate_mask *mask) |
| 1672 | { |
| 1673 | struct ath9k_htc_priv *priv = hw->priv; |
| 1674 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 1675 | struct ath9k_htc_target_rate_mask tmask; |
| 1676 | struct ath9k_htc_vif *avp = (void *)vif->drv_priv; |
| 1677 | int ret = 0; |
| 1678 | u8 cmd_rsp; |
| 1679 | |
| 1680 | memset(&tmask, 0, sizeof(struct ath9k_htc_target_rate_mask)); |
| 1681 | |
| 1682 | tmask.vif_index = avp->index; |
| 1683 | tmask.band = IEEE80211_BAND_2GHZ; |
| 1684 | tmask.mask = cpu_to_be32(mask->control[IEEE80211_BAND_2GHZ].legacy); |
| 1685 | |
| 1686 | WMI_CMD_BUF(WMI_BITRATE_MASK_CMDID, &tmask); |
| 1687 | if (ret) { |
| 1688 | ath_err(common, |
| 1689 | "Unable to set 2G rate mask for " |
| 1690 | "interface at idx: %d\n", avp->index); |
| 1691 | goto out; |
| 1692 | } |
| 1693 | |
| 1694 | tmask.band = IEEE80211_BAND_5GHZ; |
| 1695 | tmask.mask = cpu_to_be32(mask->control[IEEE80211_BAND_5GHZ].legacy); |
| 1696 | |
| 1697 | WMI_CMD_BUF(WMI_BITRATE_MASK_CMDID, &tmask); |
| 1698 | if (ret) { |
| 1699 | ath_err(common, |
| 1700 | "Unable to set 5G rate mask for " |
| 1701 | "interface at idx: %d\n", avp->index); |
| 1702 | goto out; |
| 1703 | } |
| 1704 | |
| 1705 | ath_dbg(common, ATH_DBG_CONFIG, |
| 1706 | "Set bitrate masks: 0x%x, 0x%x\n", |
| 1707 | mask->control[IEEE80211_BAND_2GHZ].legacy, |
| 1708 | mask->control[IEEE80211_BAND_5GHZ].legacy); |
| 1709 | out: |
| 1710 | return ret; |
| 1711 | } |
| 1712 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1713 | struct ieee80211_ops ath9k_htc_ops = { |
| 1714 | .tx = ath9k_htc_tx, |
| 1715 | .start = ath9k_htc_start, |
| 1716 | .stop = ath9k_htc_stop, |
| 1717 | .add_interface = ath9k_htc_add_interface, |
| 1718 | .remove_interface = ath9k_htc_remove_interface, |
| 1719 | .config = ath9k_htc_config, |
| 1720 | .configure_filter = ath9k_htc_configure_filter, |
Sujith | abd984e | 2010-05-18 15:26:04 +0530 | [diff] [blame] | 1721 | .sta_add = ath9k_htc_sta_add, |
| 1722 | .sta_remove = ath9k_htc_sta_remove, |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1723 | .conf_tx = ath9k_htc_conf_tx, |
| 1724 | .bss_info_changed = ath9k_htc_bss_info_changed, |
| 1725 | .set_key = ath9k_htc_set_key, |
| 1726 | .get_tsf = ath9k_htc_get_tsf, |
| 1727 | .set_tsf = ath9k_htc_set_tsf, |
| 1728 | .reset_tsf = ath9k_htc_reset_tsf, |
| 1729 | .ampdu_action = ath9k_htc_ampdu_action, |
| 1730 | .sw_scan_start = ath9k_htc_sw_scan_start, |
| 1731 | .sw_scan_complete = ath9k_htc_sw_scan_complete, |
| 1732 | .set_rts_threshold = ath9k_htc_set_rts_threshold, |
| 1733 | .rfkill_poll = ath9k_htc_rfkill_poll_state, |
| 1734 | .set_coverage_class = ath9k_htc_set_coverage_class, |
Sujith Manoharan | e2186b7 | 2011-04-27 17:13:40 +0530 | [diff] [blame] | 1735 | .set_bitrate_mask = ath9k_htc_set_bitrate_mask, |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1736 | }; |