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); |
| 335 | priv->nvifs--; |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 336 | priv->vif_slot &= ~(1 << priv->mon_vif_idx); |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | static int ath9k_htc_add_monitor_interface(struct ath9k_htc_priv *priv) |
| 340 | { |
| 341 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 342 | struct ath9k_htc_target_vif hvif; |
| 343 | struct ath9k_htc_target_sta tsta; |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 344 | int ret = 0, sta_idx; |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 345 | u8 cmd_rsp; |
| 346 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 347 | if ((priv->nvifs >= ATH9K_HTC_MAX_VIF) || |
| 348 | (priv->nstations >= ATH9K_HTC_MAX_STA)) { |
| 349 | ret = -ENOBUFS; |
| 350 | goto err_vif; |
| 351 | } |
Rajkumar Manoharan | 81fc2a3 | 2010-11-26 23:24:33 +0530 | [diff] [blame] | 352 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 353 | sta_idx = ffz(priv->sta_slot); |
| 354 | if ((sta_idx < 0) || (sta_idx > ATH9K_HTC_MAX_STA)) { |
| 355 | ret = -ENOBUFS; |
| 356 | goto err_vif; |
| 357 | } |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 358 | |
| 359 | /* |
| 360 | * Add an interface. |
| 361 | */ |
Rajkumar Manoharan | 81fc2a3 | 2010-11-26 23:24:33 +0530 | [diff] [blame] | 362 | memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif)); |
| 363 | memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN); |
| 364 | |
Sujith Manoharan | e4c6250 | 2011-04-13 11:24:43 +0530 | [diff] [blame] | 365 | hvif.opmode = HTC_M_MONITOR; |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 366 | hvif.index = ffz(priv->vif_slot); |
Rajkumar Manoharan | 81fc2a3 | 2010-11-26 23:24:33 +0530 | [diff] [blame] | 367 | |
| 368 | WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif); |
| 369 | if (ret) |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 370 | goto err_vif; |
| 371 | |
| 372 | /* |
| 373 | * Assign the monitor interface index as a special case here. |
| 374 | * This is needed when the interface is brought down. |
| 375 | */ |
| 376 | priv->mon_vif_idx = hvif.index; |
| 377 | priv->vif_slot |= (1 << hvif.index); |
| 378 | |
| 379 | /* |
| 380 | * Set the hardware mode to monitor only if there are no |
| 381 | * other interfaces. |
| 382 | */ |
| 383 | if (!priv->nvifs) |
| 384 | priv->ah->opmode = NL80211_IFTYPE_MONITOR; |
Rajkumar Manoharan | 81fc2a3 | 2010-11-26 23:24:33 +0530 | [diff] [blame] | 385 | |
| 386 | priv->nvifs++; |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 387 | |
| 388 | /* |
| 389 | * Associate a station with the interface for packet injection. |
| 390 | */ |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 391 | memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta)); |
| 392 | |
| 393 | memcpy(&tsta.macaddr, common->macaddr, ETH_ALEN); |
| 394 | |
| 395 | tsta.is_vif_sta = 1; |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 396 | tsta.sta_index = sta_idx; |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 397 | tsta.vif_index = hvif.index; |
Sujith Manoharan | b97c57f | 2011-04-13 11:24:37 +0530 | [diff] [blame] | 398 | tsta.maxampdu = cpu_to_be16(0xffff); |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 399 | |
| 400 | WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta); |
| 401 | if (ret) { |
| 402 | ath_err(common, "Unable to add station entry for monitor mode\n"); |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 403 | goto err_sta; |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 404 | } |
| 405 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 406 | priv->sta_slot |= (1 << sta_idx); |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 407 | priv->nstations++; |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 408 | priv->vif_sta_pos[priv->mon_vif_idx] = sta_idx; |
Sujith Manoharan | 55de80d | 2011-01-05 01:06:21 +0530 | [diff] [blame] | 409 | priv->ah->is_monitoring = true; |
| 410 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 411 | ath_dbg(common, ATH_DBG_CONFIG, |
| 412 | "Attached a monitor interface at idx: %d, sta idx: %d\n", |
| 413 | priv->mon_vif_idx, sta_idx); |
| 414 | |
Rajkumar Manoharan | 81fc2a3 | 2010-11-26 23:24:33 +0530 | [diff] [blame] | 415 | return 0; |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 416 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 417 | err_sta: |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 418 | /* |
| 419 | * Remove the interface from the target. |
| 420 | */ |
| 421 | __ath9k_htc_remove_monitor_interface(priv); |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 422 | err_vif: |
| 423 | ath_dbg(common, ATH_DBG_FATAL, "Unable to attach a monitor interface\n"); |
| 424 | |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 425 | return ret; |
Rajkumar Manoharan | 81fc2a3 | 2010-11-26 23:24:33 +0530 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | static int ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv) |
| 429 | { |
| 430 | struct ath_common *common = ath9k_hw_common(priv->ah); |
Rajkumar Manoharan | 81fc2a3 | 2010-11-26 23:24:33 +0530 | [diff] [blame] | 431 | int ret = 0; |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 432 | u8 cmd_rsp, sta_idx; |
Rajkumar Manoharan | 81fc2a3 | 2010-11-26 23:24:33 +0530 | [diff] [blame] | 433 | |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 434 | __ath9k_htc_remove_monitor_interface(priv); |
Rajkumar Manoharan | 81fc2a3 | 2010-11-26 23:24:33 +0530 | [diff] [blame] | 435 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 436 | sta_idx = priv->vif_sta_pos[priv->mon_vif_idx]; |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 437 | |
| 438 | WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx); |
| 439 | if (ret) { |
| 440 | ath_err(common, "Unable to remove station entry for monitor mode\n"); |
| 441 | return ret; |
| 442 | } |
| 443 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 444 | priv->sta_slot &= ~(1 << sta_idx); |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 445 | priv->nstations--; |
Sujith Manoharan | 55de80d | 2011-01-05 01:06:21 +0530 | [diff] [blame] | 446 | priv->ah->is_monitoring = false; |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 447 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 448 | ath_dbg(common, ATH_DBG_CONFIG, |
| 449 | "Removed a monitor interface at idx: %d, sta idx: %d\n", |
| 450 | priv->mon_vif_idx, sta_idx); |
| 451 | |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 452 | return 0; |
Rajkumar Manoharan | 81fc2a3 | 2010-11-26 23:24:33 +0530 | [diff] [blame] | 453 | } |
| 454 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 455 | static int ath9k_htc_add_station(struct ath9k_htc_priv *priv, |
| 456 | struct ieee80211_vif *vif, |
| 457 | struct ieee80211_sta *sta) |
| 458 | { |
| 459 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 460 | struct ath9k_htc_target_sta tsta; |
| 461 | struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv; |
| 462 | struct ath9k_htc_sta *ista; |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 463 | int ret, sta_idx; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 464 | u8 cmd_rsp; |
| 465 | |
| 466 | if (priv->nstations >= ATH9K_HTC_MAX_STA) |
| 467 | return -ENOBUFS; |
| 468 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 469 | sta_idx = ffz(priv->sta_slot); |
| 470 | if ((sta_idx < 0) || (sta_idx > ATH9K_HTC_MAX_STA)) |
| 471 | return -ENOBUFS; |
| 472 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 473 | memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta)); |
| 474 | |
| 475 | if (sta) { |
| 476 | ista = (struct ath9k_htc_sta *) sta->drv_priv; |
| 477 | memcpy(&tsta.macaddr, sta->addr, ETH_ALEN); |
| 478 | memcpy(&tsta.bssid, common->curbssid, ETH_ALEN); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 479 | tsta.is_vif_sta = 0; |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 480 | ista->index = sta_idx; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 481 | } else { |
| 482 | memcpy(&tsta.macaddr, vif->addr, ETH_ALEN); |
| 483 | tsta.is_vif_sta = 1; |
| 484 | } |
| 485 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 486 | tsta.sta_index = sta_idx; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 487 | tsta.vif_index = avp->index; |
Sujith Manoharan | b97c57f | 2011-04-13 11:24:37 +0530 | [diff] [blame] | 488 | tsta.maxampdu = cpu_to_be16(0xffff); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 489 | if (sta && sta->ht_cap.ht_supported) |
| 490 | tsta.flags = cpu_to_be16(ATH_HTC_STA_HT); |
| 491 | |
| 492 | WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta); |
| 493 | if (ret) { |
| 494 | if (sta) |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 495 | ath_err(common, |
| 496 | "Unable to add station entry for: %pM\n", |
| 497 | sta->addr); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 498 | return ret; |
| 499 | } |
| 500 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 501 | if (sta) { |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 502 | ath_dbg(common, ATH_DBG_CONFIG, |
| 503 | "Added a station entry for: %pM (idx: %d)\n", |
| 504 | sta->addr, tsta.sta_index); |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 505 | } else { |
| 506 | ath_dbg(common, ATH_DBG_CONFIG, |
| 507 | "Added a station entry for VIF %d (idx: %d)\n", |
| 508 | avp->index, tsta.sta_index); |
| 509 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 510 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 511 | priv->sta_slot |= (1 << sta_idx); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 512 | priv->nstations++; |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 513 | if (!sta) |
| 514 | priv->vif_sta_pos[avp->index] = sta_idx; |
| 515 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 516 | return 0; |
| 517 | } |
| 518 | |
| 519 | static int ath9k_htc_remove_station(struct ath9k_htc_priv *priv, |
| 520 | struct ieee80211_vif *vif, |
| 521 | struct ieee80211_sta *sta) |
| 522 | { |
| 523 | struct ath_common *common = ath9k_hw_common(priv->ah); |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 524 | struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 525 | struct ath9k_htc_sta *ista; |
| 526 | int ret; |
| 527 | u8 cmd_rsp, sta_idx; |
| 528 | |
| 529 | if (sta) { |
| 530 | ista = (struct ath9k_htc_sta *) sta->drv_priv; |
| 531 | sta_idx = ista->index; |
| 532 | } else { |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 533 | sta_idx = priv->vif_sta_pos[avp->index]; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx); |
| 537 | if (ret) { |
| 538 | if (sta) |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 539 | ath_err(common, |
| 540 | "Unable to remove station entry for: %pM\n", |
| 541 | sta->addr); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 542 | return ret; |
| 543 | } |
| 544 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 545 | if (sta) { |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 546 | ath_dbg(common, ATH_DBG_CONFIG, |
| 547 | "Removed a station entry for: %pM (idx: %d)\n", |
| 548 | sta->addr, sta_idx); |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 549 | } else { |
| 550 | ath_dbg(common, ATH_DBG_CONFIG, |
| 551 | "Removed a station entry for VIF %d (idx: %d)\n", |
| 552 | avp->index, sta_idx); |
| 553 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 554 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 555 | priv->sta_slot &= ~(1 << sta_idx); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 556 | priv->nstations--; |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 557 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 558 | return 0; |
| 559 | } |
| 560 | |
Sujith Manoharan | 55de80d | 2011-01-05 01:06:21 +0530 | [diff] [blame] | 561 | int ath9k_htc_update_cap_target(struct ath9k_htc_priv *priv) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 562 | { |
| 563 | struct ath9k_htc_cap_target tcap; |
| 564 | int ret; |
| 565 | u8 cmd_rsp; |
| 566 | |
| 567 | memset(&tcap, 0, sizeof(struct ath9k_htc_cap_target)); |
| 568 | |
| 569 | /* FIXME: Values are hardcoded */ |
| 570 | tcap.flags = 0x240c40; |
| 571 | tcap.flags_ext = 0x80601000; |
| 572 | tcap.ampdu_limit = 0xffff0000; |
| 573 | tcap.ampdu_subframes = 20; |
Sujith | 29d9075 | 2010-06-02 15:53:43 +0530 | [diff] [blame] | 574 | tcap.tx_chainmask_legacy = priv->ah->caps.tx_chainmask; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 575 | tcap.protmode = 1; |
Sujith | 29d9075 | 2010-06-02 15:53:43 +0530 | [diff] [blame] | 576 | tcap.tx_chainmask = priv->ah->caps.tx_chainmask; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 577 | |
| 578 | WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID, &tcap); |
| 579 | |
| 580 | return ret; |
| 581 | } |
| 582 | |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 583 | static void ath9k_htc_setup_rate(struct ath9k_htc_priv *priv, |
| 584 | struct ieee80211_sta *sta, |
| 585 | struct ath9k_htc_target_rate *trate) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 586 | { |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 587 | struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv; |
| 588 | struct ieee80211_supported_band *sband; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 589 | u32 caps = 0; |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 590 | int i, j; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 591 | |
Sujith | ea46e64 | 2010-06-02 15:53:50 +0530 | [diff] [blame] | 592 | sband = priv->hw->wiphy->bands[priv->hw->conf.channel->band]; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 593 | |
| 594 | for (i = 0, j = 0; i < sband->n_bitrates; i++) { |
| 595 | if (sta->supp_rates[sband->band] & BIT(i)) { |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 596 | trate->rates.legacy_rates.rs_rates[j] |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 597 | = (sband->bitrates[i].bitrate * 2) / 10; |
| 598 | j++; |
| 599 | } |
| 600 | } |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 601 | trate->rates.legacy_rates.rs_nrates = j; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 602 | |
| 603 | if (sta->ht_cap.ht_supported) { |
| 604 | for (i = 0, j = 0; i < 77; i++) { |
| 605 | if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8))) |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 606 | trate->rates.ht_rates.rs_rates[j++] = i; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 607 | if (j == ATH_HTC_RATE_MAX) |
| 608 | break; |
| 609 | } |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 610 | trate->rates.ht_rates.rs_nrates = j; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 611 | |
| 612 | caps = WLAN_RC_HT_FLAG; |
Felix Fietkau | 3553727 | 2010-06-12 17:22:33 +0200 | [diff] [blame] | 613 | if (sta->ht_cap.mcs.rx_mask[1]) |
| 614 | caps |= WLAN_RC_DS_FLAG; |
Vivek Natarajan | 71ba186 | 2010-08-12 14:23:28 +0530 | [diff] [blame] | 615 | if ((sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) && |
| 616 | (conf_is_ht40(&priv->hw->conf))) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 617 | caps |= WLAN_RC_40_FLAG; |
Sujith | b4dec5e | 2010-05-17 12:01:19 +0530 | [diff] [blame] | 618 | if (conf_is_ht40(&priv->hw->conf) && |
| 619 | (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40)) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 620 | caps |= WLAN_RC_SGI_FLAG; |
Sujith | b4dec5e | 2010-05-17 12:01:19 +0530 | [diff] [blame] | 621 | else if (conf_is_ht20(&priv->hw->conf) && |
| 622 | (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20)) |
| 623 | caps |= WLAN_RC_SGI_FLAG; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 624 | } |
| 625 | |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 626 | trate->sta_index = ista->index; |
| 627 | trate->isnew = 1; |
| 628 | trate->capflags = cpu_to_be32(caps); |
| 629 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 630 | |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 631 | static int ath9k_htc_send_rate_cmd(struct ath9k_htc_priv *priv, |
| 632 | struct ath9k_htc_target_rate *trate) |
| 633 | { |
| 634 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 635 | int ret; |
| 636 | u8 cmd_rsp; |
| 637 | |
| 638 | WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID, trate); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 639 | if (ret) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 640 | ath_err(common, |
| 641 | "Unable to initialize Rate information on target\n"); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 642 | } |
| 643 | |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 644 | return ret; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 645 | } |
| 646 | |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 647 | static void ath9k_htc_init_rate(struct ath9k_htc_priv *priv, |
| 648 | struct ieee80211_sta *sta) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 649 | { |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 650 | struct ath_common *common = ath9k_hw_common(priv->ah); |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 651 | struct ath9k_htc_target_rate trate; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 652 | int ret; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 653 | |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 654 | memset(&trate, 0, sizeof(struct ath9k_htc_target_rate)); |
| 655 | ath9k_htc_setup_rate(priv, sta, &trate); |
| 656 | ret = ath9k_htc_send_rate_cmd(priv, &trate); |
| 657 | if (!ret) |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 658 | ath_dbg(common, ATH_DBG_CONFIG, |
| 659 | "Updated target sta: %pM, rate caps: 0x%X\n", |
| 660 | sta->addr, be32_to_cpu(trate.capflags)); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 661 | } |
| 662 | |
Sujith | 2c76ef8 | 2010-05-17 12:01:18 +0530 | [diff] [blame] | 663 | static void ath9k_htc_update_rate(struct ath9k_htc_priv *priv, |
| 664 | struct ieee80211_vif *vif, |
| 665 | struct ieee80211_bss_conf *bss_conf) |
| 666 | { |
| 667 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 668 | struct ath9k_htc_target_rate trate; |
| 669 | struct ieee80211_sta *sta; |
| 670 | int ret; |
| 671 | |
| 672 | memset(&trate, 0, sizeof(struct ath9k_htc_target_rate)); |
| 673 | |
| 674 | rcu_read_lock(); |
| 675 | sta = ieee80211_find_sta(vif, bss_conf->bssid); |
| 676 | if (!sta) { |
| 677 | rcu_read_unlock(); |
| 678 | return; |
| 679 | } |
| 680 | ath9k_htc_setup_rate(priv, sta, &trate); |
| 681 | rcu_read_unlock(); |
| 682 | |
| 683 | ret = ath9k_htc_send_rate_cmd(priv, &trate); |
| 684 | if (!ret) |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 685 | ath_dbg(common, ATH_DBG_CONFIG, |
| 686 | "Updated target sta: %pM, rate caps: 0x%X\n", |
| 687 | bss_conf->bssid, be32_to_cpu(trate.capflags)); |
Sujith | 2c76ef8 | 2010-05-17 12:01:18 +0530 | [diff] [blame] | 688 | } |
| 689 | |
Luis R. Rodriguez | 9edd952 | 2010-07-13 21:27:25 -0400 | [diff] [blame] | 690 | static int ath9k_htc_tx_aggr_oper(struct ath9k_htc_priv *priv, |
| 691 | struct ieee80211_vif *vif, |
| 692 | struct ieee80211_sta *sta, |
| 693 | enum ieee80211_ampdu_mlme_action action, |
| 694 | u16 tid) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 695 | { |
| 696 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 697 | struct ath9k_htc_target_aggr aggr; |
Dan Carpenter | 277a64d | 2010-05-08 18:23:20 +0200 | [diff] [blame] | 698 | struct ath9k_htc_sta *ista; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 699 | int ret = 0; |
| 700 | u8 cmd_rsp; |
| 701 | |
Dan Carpenter | 0730d11 | 2010-05-08 18:24:02 +0200 | [diff] [blame] | 702 | if (tid >= ATH9K_HTC_MAX_TID) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 703 | return -EINVAL; |
| 704 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 705 | memset(&aggr, 0, sizeof(struct ath9k_htc_target_aggr)); |
Sujith | ef98c3c | 2010-03-29 16:07:11 +0530 | [diff] [blame] | 706 | ista = (struct ath9k_htc_sta *) sta->drv_priv; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 707 | |
Sujith | ef98c3c | 2010-03-29 16:07:11 +0530 | [diff] [blame] | 708 | aggr.sta_index = ista->index; |
Sujith | d7ca213 | 2010-06-15 10:24:37 +0530 | [diff] [blame] | 709 | aggr.tidno = tid & 0xf; |
| 710 | aggr.aggr_enable = (action == IEEE80211_AMPDU_TX_START) ? true : false; |
Sujith | ef98c3c | 2010-03-29 16:07:11 +0530 | [diff] [blame] | 711 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 712 | WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID, &aggr); |
| 713 | if (ret) |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 714 | ath_dbg(common, ATH_DBG_CONFIG, |
| 715 | "Unable to %s TX aggregation for (%pM, %d)\n", |
| 716 | (aggr.aggr_enable) ? "start" : "stop", sta->addr, tid); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 717 | else |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 718 | ath_dbg(common, ATH_DBG_CONFIG, |
| 719 | "%s TX aggregation for (%pM, %d)\n", |
| 720 | (aggr.aggr_enable) ? "Starting" : "Stopping", |
| 721 | sta->addr, tid); |
Sujith | d7ca213 | 2010-06-15 10:24:37 +0530 | [diff] [blame] | 722 | |
Sujith Manoharan | 658ef04 | 2011-04-13 11:25:00 +0530 | [diff] [blame] | 723 | spin_lock_bh(&priv->tx.tx_lock); |
Sujith | d7ca213 | 2010-06-15 10:24:37 +0530 | [diff] [blame] | 724 | ista->tid_state[tid] = (aggr.aggr_enable && !ret) ? AGGR_START : AGGR_STOP; |
Sujith Manoharan | 658ef04 | 2011-04-13 11:25:00 +0530 | [diff] [blame] | 725 | spin_unlock_bh(&priv->tx.tx_lock); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 726 | |
| 727 | return ret; |
| 728 | } |
| 729 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 730 | /*******/ |
| 731 | /* ANI */ |
| 732 | /*******/ |
| 733 | |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 734 | void ath9k_htc_start_ani(struct ath9k_htc_priv *priv) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 735 | { |
| 736 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 737 | unsigned long timestamp = jiffies_to_msecs(jiffies); |
| 738 | |
| 739 | common->ani.longcal_timer = timestamp; |
| 740 | common->ani.shortcal_timer = timestamp; |
| 741 | common->ani.checkani_timer = timestamp; |
| 742 | |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 743 | priv->op_flags |= OP_ANI_RUNNING; |
| 744 | |
| 745 | ieee80211_queue_delayed_work(common->hw, &priv->ani_work, |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 746 | msecs_to_jiffies(ATH_ANI_POLLINTERVAL)); |
| 747 | } |
| 748 | |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 749 | void ath9k_htc_stop_ani(struct ath9k_htc_priv *priv) |
| 750 | { |
| 751 | cancel_delayed_work_sync(&priv->ani_work); |
| 752 | priv->op_flags &= ~OP_ANI_RUNNING; |
| 753 | } |
| 754 | |
| 755 | void ath9k_htc_ani_work(struct work_struct *work) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 756 | { |
| 757 | struct ath9k_htc_priv *priv = |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 758 | container_of(work, struct ath9k_htc_priv, ani_work.work); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 759 | struct ath_hw *ah = priv->ah; |
| 760 | struct ath_common *common = ath9k_hw_common(ah); |
| 761 | bool longcal = false; |
| 762 | bool shortcal = false; |
| 763 | bool aniflag = false; |
| 764 | unsigned int timestamp = jiffies_to_msecs(jiffies); |
| 765 | u32 cal_interval, short_cal_interval; |
| 766 | |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 767 | short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ? |
| 768 | ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 769 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 770 | /* Only calibrate if awake */ |
| 771 | if (ah->power_mode != ATH9K_PM_AWAKE) |
| 772 | goto set_timer; |
| 773 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 774 | /* Long calibration runs independently of short calibration. */ |
| 775 | if ((timestamp - common->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) { |
| 776 | longcal = true; |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 777 | ath_dbg(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 778 | common->ani.longcal_timer = timestamp; |
| 779 | } |
| 780 | |
| 781 | /* Short calibration applies only while caldone is false */ |
| 782 | if (!common->ani.caldone) { |
| 783 | if ((timestamp - common->ani.shortcal_timer) >= |
| 784 | short_cal_interval) { |
| 785 | shortcal = true; |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 786 | ath_dbg(common, ATH_DBG_ANI, |
| 787 | "shortcal @%lu\n", jiffies); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 788 | common->ani.shortcal_timer = timestamp; |
| 789 | common->ani.resetcal_timer = timestamp; |
| 790 | } |
| 791 | } else { |
| 792 | if ((timestamp - common->ani.resetcal_timer) >= |
| 793 | ATH_RESTART_CALINTERVAL) { |
| 794 | common->ani.caldone = ath9k_hw_reset_calvalid(ah); |
| 795 | if (common->ani.caldone) |
| 796 | common->ani.resetcal_timer = timestamp; |
| 797 | } |
| 798 | } |
| 799 | |
| 800 | /* Verify whether we must check ANI */ |
| 801 | if ((timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) { |
| 802 | aniflag = true; |
| 803 | common->ani.checkani_timer = timestamp; |
| 804 | } |
| 805 | |
| 806 | /* Skip all processing if there's nothing to do. */ |
| 807 | if (longcal || shortcal || aniflag) { |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 808 | |
| 809 | ath9k_htc_ps_wakeup(priv); |
| 810 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 811 | /* Call ANI routine if necessary */ |
| 812 | if (aniflag) |
| 813 | ath9k_hw_ani_monitor(ah, ah->curchan); |
| 814 | |
| 815 | /* Perform calibration if necessary */ |
Felix Fietkau | 35ecfe0 | 2010-09-29 17:15:26 +0200 | [diff] [blame] | 816 | if (longcal || shortcal) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 817 | common->ani.caldone = |
| 818 | ath9k_hw_calibrate(ah, ah->curchan, |
| 819 | common->rx_chainmask, |
| 820 | longcal); |
| 821 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 822 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 823 | } |
| 824 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 825 | set_timer: |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 826 | /* |
| 827 | * Set timer interval based on previous results. |
| 828 | * The interval must be the shortest necessary to satisfy ANI, |
| 829 | * short calibration and long calibration. |
| 830 | */ |
| 831 | cal_interval = ATH_LONG_CALINTERVAL; |
| 832 | if (priv->ah->config.enable_ani) |
| 833 | cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL); |
| 834 | if (!common->ani.caldone) |
| 835 | cal_interval = min(cal_interval, (u32)short_cal_interval); |
| 836 | |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 837 | ieee80211_queue_delayed_work(common->hw, &priv->ani_work, |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 838 | msecs_to_jiffies(cal_interval)); |
| 839 | } |
| 840 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 841 | /**********************/ |
| 842 | /* mac80211 Callbacks */ |
| 843 | /**********************/ |
| 844 | |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 845 | static void ath9k_htc_tx(struct ieee80211_hw *hw, struct sk_buff *skb) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 846 | { |
| 847 | struct ieee80211_hdr *hdr; |
| 848 | struct ath9k_htc_priv *priv = hw->priv; |
Sujith Manoharan | 8e86a54 | 2011-04-13 11:25:29 +0530 | [diff] [blame] | 849 | struct ath_common *common = ath9k_hw_common(priv->ah); |
Sujith Manoharan | 2c5d57f | 2011-04-13 11:25:47 +0530 | [diff] [blame] | 850 | int padpos, padsize, ret, slot; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 851 | |
| 852 | hdr = (struct ieee80211_hdr *) skb->data; |
| 853 | |
| 854 | /* Add the padding after the header if this is not already done */ |
| 855 | padpos = ath9k_cmn_padpos(hdr->frame_control); |
| 856 | padsize = padpos & 3; |
| 857 | if (padsize && skb->len > padpos) { |
Sujith Manoharan | 8e86a54 | 2011-04-13 11:25:29 +0530 | [diff] [blame] | 858 | if (skb_headroom(skb) < padsize) { |
| 859 | ath_dbg(common, ATH_DBG_XMIT, "No room for padding\n"); |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 860 | goto fail_tx; |
Sujith Manoharan | 8e86a54 | 2011-04-13 11:25:29 +0530 | [diff] [blame] | 861 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 862 | skb_push(skb, padsize); |
| 863 | memmove(skb->data, skb->data + padsize, padpos); |
| 864 | } |
| 865 | |
Sujith Manoharan | 2c5d57f | 2011-04-13 11:25:47 +0530 | [diff] [blame] | 866 | slot = ath9k_htc_tx_get_slot(priv); |
| 867 | if (slot < 0) { |
| 868 | ath_dbg(common, ATH_DBG_XMIT, "No free TX slot\n"); |
| 869 | goto fail_tx; |
| 870 | } |
| 871 | |
| 872 | ret = ath9k_htc_tx_start(priv, skb, slot, false); |
Sujith | 7757dfe | 2010-03-29 16:07:17 +0530 | [diff] [blame] | 873 | if (ret != 0) { |
Sujith Manoharan | 8e86a54 | 2011-04-13 11:25:29 +0530 | [diff] [blame] | 874 | ath_dbg(common, ATH_DBG_XMIT, "Tx failed\n"); |
Sujith Manoharan | 2c5d57f | 2011-04-13 11:25:47 +0530 | [diff] [blame] | 875 | goto clear_slot; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 876 | } |
| 877 | |
Sujith Manoharan | 8e86a54 | 2011-04-13 11:25:29 +0530 | [diff] [blame] | 878 | ath9k_htc_check_stop_queues(priv); |
| 879 | |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 880 | return; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 881 | |
Sujith Manoharan | 2c5d57f | 2011-04-13 11:25:47 +0530 | [diff] [blame] | 882 | clear_slot: |
| 883 | ath9k_htc_tx_clear_slot(priv, slot); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 884 | fail_tx: |
| 885 | dev_kfree_skb_any(skb); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 886 | } |
| 887 | |
Sujith | 881ac6a | 2010-06-01 15:14:11 +0530 | [diff] [blame] | 888 | static int ath9k_htc_start(struct ieee80211_hw *hw) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 889 | { |
| 890 | struct ath9k_htc_priv *priv = hw->priv; |
| 891 | struct ath_hw *ah = priv->ah; |
| 892 | struct ath_common *common = ath9k_hw_common(ah); |
| 893 | struct ieee80211_channel *curchan = hw->conf.channel; |
| 894 | struct ath9k_channel *init_channel; |
| 895 | int ret = 0; |
| 896 | enum htc_phymode mode; |
Sujith | 7f1f5a0 | 2010-04-16 11:54:03 +0530 | [diff] [blame] | 897 | __be16 htc_mode; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 898 | u8 cmd_rsp; |
| 899 | |
Sujith | 881ac6a | 2010-06-01 15:14:11 +0530 | [diff] [blame] | 900 | mutex_lock(&priv->mutex); |
| 901 | |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 902 | ath_dbg(common, ATH_DBG_CONFIG, |
| 903 | "Starting driver with initial channel: %d MHz\n", |
| 904 | curchan->center_freq); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 905 | |
Sujith | 21d5130 | 2010-06-01 15:14:18 +0530 | [diff] [blame] | 906 | /* Ensure that HW is awake before flushing RX */ |
| 907 | ath9k_htc_setpower(priv, ATH9K_PM_AWAKE); |
| 908 | WMI_CMD(WMI_FLUSH_RECV_CMDID); |
| 909 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 910 | /* setup initial channel */ |
| 911 | init_channel = ath9k_cmn_get_curchannel(hw, ah); |
| 912 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 913 | ath9k_hw_htc_resetinit(ah); |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 914 | ret = ath9k_hw_reset(ah, init_channel, ah->caldata, false); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 915 | if (ret) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 916 | ath_err(common, |
| 917 | "Unable to reset hardware; reset status %d (freq %u MHz)\n", |
| 918 | ret, curchan->center_freq); |
Sujith | 881ac6a | 2010-06-01 15:14:11 +0530 | [diff] [blame] | 919 | mutex_unlock(&priv->mutex); |
Vivek Natarajan | 8a8572a | 2010-04-27 13:05:37 +0530 | [diff] [blame] | 920 | return ret; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 921 | } |
| 922 | |
Rajkumar Manoharan | b2a5c3d | 2011-01-31 23:47:45 +0530 | [diff] [blame] | 923 | ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit, |
| 924 | &priv->curtxpow); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 925 | |
| 926 | mode = ath9k_htc_get_curmode(priv, init_channel); |
| 927 | htc_mode = cpu_to_be16(mode); |
| 928 | WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 929 | WMI_CMD(WMI_ATH_INIT_CMDID); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 930 | WMI_CMD(WMI_START_RECV_CMDID); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 931 | |
| 932 | ath9k_host_rx_init(priv); |
| 933 | |
Sujith Manoharan | 1057b75 | 2011-02-21 07:48:09 +0530 | [diff] [blame] | 934 | ret = ath9k_htc_update_cap_target(priv); |
| 935 | if (ret) |
| 936 | ath_dbg(common, ATH_DBG_CONFIG, |
| 937 | "Failed to update capability in target\n"); |
| 938 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 939 | priv->op_flags &= ~OP_INVALID; |
| 940 | htc_start(priv->htc); |
| 941 | |
Sujith Manoharan | 658ef04 | 2011-04-13 11:25:00 +0530 | [diff] [blame] | 942 | spin_lock_bh(&priv->tx.tx_lock); |
Sujith Manoharan | 8e86a54 | 2011-04-13 11:25:29 +0530 | [diff] [blame] | 943 | priv->tx.flags &= ~ATH9K_HTC_OP_TX_QUEUES_STOP; |
Sujith Manoharan | 658ef04 | 2011-04-13 11:25:00 +0530 | [diff] [blame] | 944 | spin_unlock_bh(&priv->tx.tx_lock); |
Sujith | 7757dfe | 2010-03-29 16:07:17 +0530 | [diff] [blame] | 945 | |
| 946 | ieee80211_wake_queues(hw); |
| 947 | |
Sujith Manoharan | 859c3ca | 2011-04-13 11:26:39 +0530 | [diff] [blame^] | 948 | mod_timer(&priv->tx.cleanup_timer, |
| 949 | jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL)); |
| 950 | |
Vivek Natarajan | 21cb987 | 2010-08-18 19:57:49 +0530 | [diff] [blame] | 951 | if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE) { |
| 952 | ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT, |
| 953 | AR_STOMP_LOW_WLAN_WGHT); |
| 954 | ath9k_hw_btcoex_enable(ah); |
| 955 | ath_htc_resume_btcoex_work(priv); |
| 956 | } |
Vivek Natarajan | 8a8572a | 2010-04-27 13:05:37 +0530 | [diff] [blame] | 957 | mutex_unlock(&priv->mutex); |
| 958 | |
| 959 | return ret; |
| 960 | } |
| 961 | |
Sujith | 881ac6a | 2010-06-01 15:14:11 +0530 | [diff] [blame] | 962 | static void ath9k_htc_stop(struct ieee80211_hw *hw) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 963 | { |
| 964 | struct ath9k_htc_priv *priv = hw->priv; |
| 965 | struct ath_hw *ah = priv->ah; |
| 966 | struct ath_common *common = ath9k_hw_common(ah); |
| 967 | int ret = 0; |
| 968 | u8 cmd_rsp; |
| 969 | |
Sujith | 881ac6a | 2010-06-01 15:14:11 +0530 | [diff] [blame] | 970 | mutex_lock(&priv->mutex); |
| 971 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 972 | if (priv->op_flags & OP_INVALID) { |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 973 | ath_dbg(common, ATH_DBG_ANY, "Device not present\n"); |
Sujith | 881ac6a | 2010-06-01 15:14:11 +0530 | [diff] [blame] | 974 | mutex_unlock(&priv->mutex); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 975 | return; |
| 976 | } |
| 977 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 978 | ath9k_htc_ps_wakeup(priv); |
Sujith Manoharan | b587fc8 | 2011-04-13 11:25:59 +0530 | [diff] [blame] | 979 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 980 | WMI_CMD(WMI_DISABLE_INTR_CMDID); |
| 981 | WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID); |
| 982 | WMI_CMD(WMI_STOP_RECV_CMDID); |
Stanislaw Gruszka | ea88835 | 2011-01-25 14:15:12 +0100 | [diff] [blame] | 983 | |
Stanislaw Gruszka | ea88835 | 2011-01-25 14:15:12 +0100 | [diff] [blame] | 984 | tasklet_kill(&priv->rx_tasklet); |
Stanislaw Gruszka | ea88835 | 2011-01-25 14:15:12 +0100 | [diff] [blame] | 985 | |
Sujith Manoharan | 859c3ca | 2011-04-13 11:26:39 +0530 | [diff] [blame^] | 986 | del_timer_sync(&priv->tx.cleanup_timer); |
Sujith Manoharan | b587fc8 | 2011-04-13 11:25:59 +0530 | [diff] [blame] | 987 | ath9k_htc_tx_drain(priv); |
Sujith Manoharan | f4c8899 | 2011-04-13 11:23:52 +0530 | [diff] [blame] | 988 | ath9k_wmi_event_drain(priv); |
| 989 | |
Stanislaw Gruszka | ea88835 | 2011-01-25 14:15:12 +0100 | [diff] [blame] | 990 | mutex_unlock(&priv->mutex); |
| 991 | |
| 992 | /* Cancel all the running timers/work .. */ |
| 993 | cancel_work_sync(&priv->fatal_work); |
| 994 | cancel_work_sync(&priv->ps_work); |
| 995 | cancel_delayed_work_sync(&priv->ath9k_led_blink_work); |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 996 | ath9k_htc_stop_ani(priv); |
Stanislaw Gruszka | ea88835 | 2011-01-25 14:15:12 +0100 | [diff] [blame] | 997 | ath9k_led_stop_brightness(priv); |
| 998 | |
| 999 | mutex_lock(&priv->mutex); |
| 1000 | |
Vivek Natarajan | 21cb987 | 2010-08-18 19:57:49 +0530 | [diff] [blame] | 1001 | if (ah->btcoex_hw.enabled) { |
| 1002 | ath9k_hw_btcoex_disable(ah); |
| 1003 | if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE) |
| 1004 | ath_htc_cancel_btcoex_work(priv); |
| 1005 | } |
| 1006 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 1007 | /* Remove a monitor interface if it's present. */ |
| 1008 | if (priv->ah->is_monitoring) |
| 1009 | ath9k_htc_remove_monitor_interface(priv); |
| 1010 | |
Sujith | e9201f0 | 2010-06-01 15:14:17 +0530 | [diff] [blame] | 1011 | ath9k_hw_phy_disable(ah); |
| 1012 | ath9k_hw_disable(ah); |
Sujith | e9201f0 | 2010-06-01 15:14:17 +0530 | [diff] [blame] | 1013 | ath9k_htc_ps_restore(priv); |
| 1014 | ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP); |
| 1015 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1016 | priv->op_flags |= OP_INVALID; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1017 | |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 1018 | ath_dbg(common, ATH_DBG_CONFIG, "Driver halt\n"); |
Vivek Natarajan | 8a8572a | 2010-04-27 13:05:37 +0530 | [diff] [blame] | 1019 | mutex_unlock(&priv->mutex); |
| 1020 | } |
| 1021 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1022 | static int ath9k_htc_add_interface(struct ieee80211_hw *hw, |
| 1023 | struct ieee80211_vif *vif) |
| 1024 | { |
| 1025 | struct ath9k_htc_priv *priv = hw->priv; |
| 1026 | struct ath9k_htc_vif *avp = (void *)vif->drv_priv; |
| 1027 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 1028 | struct ath9k_htc_target_vif hvif; |
| 1029 | int ret = 0; |
| 1030 | u8 cmd_rsp; |
| 1031 | |
| 1032 | mutex_lock(&priv->mutex); |
| 1033 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 1034 | if (priv->nvifs >= ATH9K_HTC_MAX_VIF) { |
Sujith Manoharan | ab77c70 | 2011-02-21 07:48:16 +0530 | [diff] [blame] | 1035 | mutex_unlock(&priv->mutex); |
Sujith Manoharan | 0df8359 | 2011-02-21 07:49:15 +0530 | [diff] [blame] | 1036 | return -ENOBUFS; |
| 1037 | } |
| 1038 | |
| 1039 | if (priv->num_ibss_vif || |
| 1040 | (priv->nvifs && vif->type == NL80211_IFTYPE_ADHOC)) { |
| 1041 | ath_err(common, "IBSS coexistence with other modes is not allowed\n"); |
| 1042 | mutex_unlock(&priv->mutex); |
| 1043 | return -ENOBUFS; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1044 | } |
| 1045 | |
Sujith Manoharan | da8d9d9 | 2011-02-21 07:49:23 +0530 | [diff] [blame] | 1046 | if (((vif->type == NL80211_IFTYPE_AP) || |
| 1047 | (vif->type == NL80211_IFTYPE_ADHOC)) && |
| 1048 | ((priv->num_ap_vif + priv->num_ibss_vif) >= ATH9K_HTC_MAX_BCN_VIF)) { |
| 1049 | ath_err(common, "Max. number of beaconing interfaces reached\n"); |
| 1050 | mutex_unlock(&priv->mutex); |
| 1051 | return -ENOBUFS; |
| 1052 | } |
| 1053 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1054 | ath9k_htc_ps_wakeup(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1055 | memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif)); |
| 1056 | memcpy(&hvif.myaddr, vif->addr, ETH_ALEN); |
| 1057 | |
| 1058 | switch (vif->type) { |
| 1059 | case NL80211_IFTYPE_STATION: |
Sujith Manoharan | e4c6250 | 2011-04-13 11:24:43 +0530 | [diff] [blame] | 1060 | hvif.opmode = HTC_M_STA; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1061 | break; |
| 1062 | case NL80211_IFTYPE_ADHOC: |
Sujith Manoharan | e4c6250 | 2011-04-13 11:24:43 +0530 | [diff] [blame] | 1063 | hvif.opmode = HTC_M_IBSS; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1064 | break; |
Sujith Manoharan | da8d9d9 | 2011-02-21 07:49:23 +0530 | [diff] [blame] | 1065 | case NL80211_IFTYPE_AP: |
Sujith Manoharan | e4c6250 | 2011-04-13 11:24:43 +0530 | [diff] [blame] | 1066 | hvif.opmode = HTC_M_HOSTAP; |
Sujith Manoharan | da8d9d9 | 2011-02-21 07:49:23 +0530 | [diff] [blame] | 1067 | break; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1068 | default: |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 1069 | ath_err(common, |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1070 | "Interface type %d not yet supported\n", vif->type); |
| 1071 | ret = -EOPNOTSUPP; |
| 1072 | goto out; |
| 1073 | } |
| 1074 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1075 | /* Index starts from zero on the target */ |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 1076 | avp->index = hvif.index = ffz(priv->vif_slot); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1077 | hvif.rtsthreshold = cpu_to_be16(2304); |
| 1078 | WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif); |
| 1079 | if (ret) |
| 1080 | goto out; |
| 1081 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1082 | /* |
| 1083 | * We need a node in target to tx mgmt frames |
| 1084 | * before association. |
| 1085 | */ |
| 1086 | ret = ath9k_htc_add_station(priv, vif, NULL); |
Sujith Manoharan | ab77c70 | 2011-02-21 07:48:16 +0530 | [diff] [blame] | 1087 | if (ret) { |
| 1088 | WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1089 | goto out; |
Sujith Manoharan | ab77c70 | 2011-02-21 07:48:16 +0530 | [diff] [blame] | 1090 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1091 | |
Sujith Manoharan | 585895c | 2011-02-21 07:48:46 +0530 | [diff] [blame] | 1092 | ath9k_htc_set_bssid_mask(priv, vif); |
| 1093 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 1094 | priv->vif_slot |= (1 << avp->index); |
Sujith Manoharan | ab77c70 | 2011-02-21 07:48:16 +0530 | [diff] [blame] | 1095 | priv->nvifs++; |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 1096 | |
Sujith Manoharan | 0df8359 | 2011-02-21 07:49:15 +0530 | [diff] [blame] | 1097 | INC_VIF(priv, vif->type); |
Sujith Manoharan | 832f6a1 | 2011-04-13 11:23:08 +0530 | [diff] [blame] | 1098 | |
| 1099 | if ((vif->type == NL80211_IFTYPE_AP) || |
| 1100 | (vif->type == NL80211_IFTYPE_ADHOC)) |
| 1101 | ath9k_htc_assign_bslot(priv, vif); |
| 1102 | |
Sujith Manoharan | ffbe7c8 | 2011-02-21 07:49:31 +0530 | [diff] [blame] | 1103 | ath9k_htc_set_opmode(priv); |
Sujith Manoharan | 0df8359 | 2011-02-21 07:49:15 +0530 | [diff] [blame] | 1104 | |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 1105 | if ((priv->ah->opmode == NL80211_IFTYPE_AP) && |
Sujith Manoharan | 9b674a0 | 2011-04-13 11:23:17 +0530 | [diff] [blame] | 1106 | !(priv->op_flags & OP_ANI_RUNNING)) { |
| 1107 | ath9k_hw_set_tsfadjust(priv->ah, 1); |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 1108 | ath9k_htc_start_ani(priv); |
Sujith Manoharan | 9b674a0 | 2011-04-13 11:23:17 +0530 | [diff] [blame] | 1109 | } |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 1110 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 1111 | ath_dbg(common, ATH_DBG_CONFIG, |
| 1112 | "Attach a VIF of type: %d at idx: %d\n", vif->type, avp->index); |
| 1113 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1114 | out: |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1115 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1116 | mutex_unlock(&priv->mutex); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1117 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1118 | return ret; |
| 1119 | } |
| 1120 | |
| 1121 | static void ath9k_htc_remove_interface(struct ieee80211_hw *hw, |
| 1122 | struct ieee80211_vif *vif) |
| 1123 | { |
| 1124 | struct ath9k_htc_priv *priv = hw->priv; |
| 1125 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 1126 | struct ath9k_htc_vif *avp = (void *)vif->drv_priv; |
| 1127 | struct ath9k_htc_target_vif hvif; |
| 1128 | int ret = 0; |
| 1129 | u8 cmd_rsp; |
| 1130 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1131 | mutex_lock(&priv->mutex); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1132 | ath9k_htc_ps_wakeup(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1133 | |
| 1134 | memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif)); |
| 1135 | memcpy(&hvif.myaddr, vif->addr, ETH_ALEN); |
| 1136 | hvif.index = avp->index; |
| 1137 | WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif); |
| 1138 | priv->nvifs--; |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 1139 | priv->vif_slot &= ~(1 << avp->index); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1140 | |
| 1141 | ath9k_htc_remove_station(priv, vif, NULL); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1142 | |
Sujith Manoharan | 0df8359 | 2011-02-21 07:49:15 +0530 | [diff] [blame] | 1143 | DEC_VIF(priv, vif->type); |
Sujith Manoharan | 832f6a1 | 2011-04-13 11:23:08 +0530 | [diff] [blame] | 1144 | |
| 1145 | if ((vif->type == NL80211_IFTYPE_AP) || |
| 1146 | (vif->type == NL80211_IFTYPE_ADHOC)) |
| 1147 | ath9k_htc_remove_bslot(priv, vif); |
| 1148 | |
Sujith Manoharan | ffbe7c8 | 2011-02-21 07:49:31 +0530 | [diff] [blame] | 1149 | ath9k_htc_set_opmode(priv); |
Sujith Manoharan | 0df8359 | 2011-02-21 07:49:15 +0530 | [diff] [blame] | 1150 | |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 1151 | /* |
| 1152 | * Stop ANI only if there are no associated station interfaces. |
| 1153 | */ |
| 1154 | if ((vif->type == NL80211_IFTYPE_AP) && (priv->num_ap_vif == 0)) { |
| 1155 | priv->rearm_ani = false; |
| 1156 | ieee80211_iterate_active_interfaces_atomic(priv->hw, |
| 1157 | ath9k_htc_vif_iter, priv); |
| 1158 | if (!priv->rearm_ani) |
| 1159 | ath9k_htc_stop_ani(priv); |
| 1160 | } |
| 1161 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 1162 | ath_dbg(common, ATH_DBG_CONFIG, "Detach Interface at idx: %d\n", avp->index); |
| 1163 | |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1164 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1165 | mutex_unlock(&priv->mutex); |
| 1166 | } |
| 1167 | |
| 1168 | static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed) |
| 1169 | { |
| 1170 | struct ath9k_htc_priv *priv = hw->priv; |
| 1171 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 1172 | struct ieee80211_conf *conf = &hw->conf; |
| 1173 | |
| 1174 | mutex_lock(&priv->mutex); |
| 1175 | |
Vivek Natarajan | 8a8572a | 2010-04-27 13:05:37 +0530 | [diff] [blame] | 1176 | if (changed & IEEE80211_CONF_CHANGE_IDLE) { |
| 1177 | bool enable_radio = false; |
| 1178 | bool idle = !!(conf->flags & IEEE80211_CONF_IDLE); |
| 1179 | |
Sujith | 2336776 | 2010-06-01 15:14:16 +0530 | [diff] [blame] | 1180 | mutex_lock(&priv->htc_pm_lock); |
Vivek Natarajan | 8a8572a | 2010-04-27 13:05:37 +0530 | [diff] [blame] | 1181 | if (!idle && priv->ps_idle) |
| 1182 | enable_radio = true; |
Vivek Natarajan | 8a8572a | 2010-04-27 13:05:37 +0530 | [diff] [blame] | 1183 | priv->ps_idle = idle; |
Sujith | 2336776 | 2010-06-01 15:14:16 +0530 | [diff] [blame] | 1184 | mutex_unlock(&priv->htc_pm_lock); |
Vivek Natarajan | 8a8572a | 2010-04-27 13:05:37 +0530 | [diff] [blame] | 1185 | |
| 1186 | if (enable_radio) { |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 1187 | ath_dbg(common, ATH_DBG_CONFIG, |
| 1188 | "not-idle: enabling radio\n"); |
Sujith | 2336776 | 2010-06-01 15:14:16 +0530 | [diff] [blame] | 1189 | ath9k_htc_setpower(priv, ATH9K_PM_AWAKE); |
| 1190 | ath9k_htc_radio_enable(hw); |
Vivek Natarajan | 8a8572a | 2010-04-27 13:05:37 +0530 | [diff] [blame] | 1191 | } |
| 1192 | } |
| 1193 | |
Sujith Manoharan | 55de80d | 2011-01-05 01:06:21 +0530 | [diff] [blame] | 1194 | /* |
| 1195 | * Monitor interface should be added before |
| 1196 | * IEEE80211_CONF_CHANGE_CHANNEL is handled. |
| 1197 | */ |
| 1198 | if (changed & IEEE80211_CONF_CHANGE_MONITOR) { |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 1199 | if ((conf->flags & IEEE80211_CONF_MONITOR) && |
| 1200 | !priv->ah->is_monitoring) |
| 1201 | ath9k_htc_add_monitor_interface(priv); |
| 1202 | else if (priv->ah->is_monitoring) |
| 1203 | ath9k_htc_remove_monitor_interface(priv); |
Sujith Manoharan | 55de80d | 2011-01-05 01:06:21 +0530 | [diff] [blame] | 1204 | } |
| 1205 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1206 | if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { |
| 1207 | struct ieee80211_channel *curchan = hw->conf.channel; |
| 1208 | int pos = curchan->hw_value; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1209 | |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 1210 | ath_dbg(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n", |
| 1211 | curchan->center_freq); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1212 | |
Felix Fietkau | babcbc2 | 2010-10-20 02:09:46 +0200 | [diff] [blame] | 1213 | ath9k_cmn_update_ichannel(&priv->ah->channels[pos], |
| 1214 | hw->conf.channel, |
| 1215 | hw->conf.channel_type); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1216 | |
| 1217 | if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 1218 | ath_err(common, "Unable to set channel\n"); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1219 | mutex_unlock(&priv->mutex); |
| 1220 | return -EINVAL; |
| 1221 | } |
| 1222 | |
| 1223 | } |
Sujith Manoharan | 692d6b1 | 2010-12-07 16:31:54 +0530 | [diff] [blame] | 1224 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1225 | if (changed & IEEE80211_CONF_CHANGE_PS) { |
| 1226 | if (conf->flags & IEEE80211_CONF_PS) { |
| 1227 | ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP); |
| 1228 | priv->ps_enabled = true; |
| 1229 | } else { |
| 1230 | priv->ps_enabled = false; |
| 1231 | cancel_work_sync(&priv->ps_work); |
| 1232 | ath9k_htc_setpower(priv, ATH9K_PM_AWAKE); |
| 1233 | } |
| 1234 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1235 | |
Sujith Manoharan | 692d6b1 | 2010-12-07 16:31:54 +0530 | [diff] [blame] | 1236 | if (changed & IEEE80211_CONF_CHANGE_POWER) { |
| 1237 | priv->txpowlimit = 2 * conf->power_level; |
Rajkumar Manoharan | b2a5c3d | 2011-01-31 23:47:45 +0530 | [diff] [blame] | 1238 | ath9k_cmn_update_txpow(priv->ah, priv->curtxpow, |
| 1239 | priv->txpowlimit, &priv->curtxpow); |
Sujith Manoharan | 692d6b1 | 2010-12-07 16:31:54 +0530 | [diff] [blame] | 1240 | } |
| 1241 | |
Sujith | 2336776 | 2010-06-01 15:14:16 +0530 | [diff] [blame] | 1242 | if (changed & IEEE80211_CONF_CHANGE_IDLE) { |
| 1243 | mutex_lock(&priv->htc_pm_lock); |
| 1244 | if (!priv->ps_idle) { |
| 1245 | mutex_unlock(&priv->htc_pm_lock); |
| 1246 | goto out; |
| 1247 | } |
| 1248 | mutex_unlock(&priv->htc_pm_lock); |
| 1249 | |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 1250 | ath_dbg(common, ATH_DBG_CONFIG, |
| 1251 | "idle: disabling radio\n"); |
Sujith | 881ac6a | 2010-06-01 15:14:11 +0530 | [diff] [blame] | 1252 | ath9k_htc_radio_disable(hw); |
Vivek Natarajan | 8a8572a | 2010-04-27 13:05:37 +0530 | [diff] [blame] | 1253 | } |
| 1254 | |
Sujith | 2336776 | 2010-06-01 15:14:16 +0530 | [diff] [blame] | 1255 | out: |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1256 | mutex_unlock(&priv->mutex); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1257 | return 0; |
| 1258 | } |
| 1259 | |
| 1260 | #define SUPPORTED_FILTERS \ |
| 1261 | (FIF_PROMISC_IN_BSS | \ |
| 1262 | FIF_ALLMULTI | \ |
| 1263 | FIF_CONTROL | \ |
| 1264 | FIF_PSPOLL | \ |
| 1265 | FIF_OTHER_BSS | \ |
| 1266 | FIF_BCN_PRBRESP_PROMISC | \ |
Rajkumar Manoharan | 94a40c0 | 2010-10-14 10:50:26 +0530 | [diff] [blame] | 1267 | FIF_PROBE_REQ | \ |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1268 | FIF_FCSFAIL) |
| 1269 | |
| 1270 | static void ath9k_htc_configure_filter(struct ieee80211_hw *hw, |
| 1271 | unsigned int changed_flags, |
| 1272 | unsigned int *total_flags, |
| 1273 | u64 multicast) |
| 1274 | { |
| 1275 | struct ath9k_htc_priv *priv = hw->priv; |
| 1276 | u32 rfilt; |
| 1277 | |
| 1278 | mutex_lock(&priv->mutex); |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1279 | ath9k_htc_ps_wakeup(priv); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1280 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1281 | changed_flags &= SUPPORTED_FILTERS; |
| 1282 | *total_flags &= SUPPORTED_FILTERS; |
| 1283 | |
| 1284 | priv->rxfilter = *total_flags; |
Sujith | 0995d11 | 2010-03-29 16:07:09 +0530 | [diff] [blame] | 1285 | rfilt = ath9k_htc_calcrxfilter(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1286 | ath9k_hw_setrxfilter(priv->ah, rfilt); |
| 1287 | |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 1288 | ath_dbg(ath9k_hw_common(priv->ah), ATH_DBG_CONFIG, |
| 1289 | "Set HW RX filter: 0x%x\n", rfilt); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1290 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1291 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1292 | mutex_unlock(&priv->mutex); |
| 1293 | } |
| 1294 | |
Sujith | abd984e | 2010-05-18 15:26:04 +0530 | [diff] [blame] | 1295 | static int ath9k_htc_sta_add(struct ieee80211_hw *hw, |
| 1296 | struct ieee80211_vif *vif, |
| 1297 | struct ieee80211_sta *sta) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1298 | { |
| 1299 | struct ath9k_htc_priv *priv = hw->priv; |
| 1300 | int ret; |
| 1301 | |
Sujith.Manoharan@atheros.com | 05a30f9 | 2010-05-11 16:24:38 +0530 | [diff] [blame] | 1302 | mutex_lock(&priv->mutex); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1303 | ath9k_htc_ps_wakeup(priv); |
Sujith | abd984e | 2010-05-18 15:26:04 +0530 | [diff] [blame] | 1304 | ret = ath9k_htc_add_station(priv, vif, sta); |
| 1305 | if (!ret) |
| 1306 | ath9k_htc_init_rate(priv, sta); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1307 | ath9k_htc_ps_restore(priv); |
Sujith.Manoharan@atheros.com | 05a30f9 | 2010-05-11 16:24:38 +0530 | [diff] [blame] | 1308 | mutex_unlock(&priv->mutex); |
Sujith | abd984e | 2010-05-18 15:26:04 +0530 | [diff] [blame] | 1309 | |
| 1310 | return ret; |
| 1311 | } |
| 1312 | |
| 1313 | static int ath9k_htc_sta_remove(struct ieee80211_hw *hw, |
| 1314 | struct ieee80211_vif *vif, |
| 1315 | struct ieee80211_sta *sta) |
| 1316 | { |
| 1317 | struct ath9k_htc_priv *priv = hw->priv; |
Sujith Manoharan | 84c9e164 | 2011-04-13 11:26:11 +0530 | [diff] [blame] | 1318 | struct ath9k_htc_sta *ista; |
Sujith | abd984e | 2010-05-18 15:26:04 +0530 | [diff] [blame] | 1319 | int ret; |
| 1320 | |
| 1321 | mutex_lock(&priv->mutex); |
| 1322 | ath9k_htc_ps_wakeup(priv); |
Sujith Manoharan | 84c9e164 | 2011-04-13 11:26:11 +0530 | [diff] [blame] | 1323 | ista = (struct ath9k_htc_sta *) sta->drv_priv; |
| 1324 | htc_sta_drain(priv->htc, ista->index); |
Sujith | abd984e | 2010-05-18 15:26:04 +0530 | [diff] [blame] | 1325 | ret = ath9k_htc_remove_station(priv, vif, sta); |
| 1326 | ath9k_htc_ps_restore(priv); |
| 1327 | mutex_unlock(&priv->mutex); |
| 1328 | |
| 1329 | return ret; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1330 | } |
| 1331 | |
| 1332 | static int ath9k_htc_conf_tx(struct ieee80211_hw *hw, u16 queue, |
| 1333 | const struct ieee80211_tx_queue_params *params) |
| 1334 | { |
| 1335 | struct ath9k_htc_priv *priv = hw->priv; |
| 1336 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 1337 | struct ath9k_tx_queue_info qi; |
| 1338 | int ret = 0, qnum; |
| 1339 | |
| 1340 | if (queue >= WME_NUM_AC) |
| 1341 | return 0; |
| 1342 | |
| 1343 | mutex_lock(&priv->mutex); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1344 | ath9k_htc_ps_wakeup(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1345 | |
| 1346 | memset(&qi, 0, sizeof(struct ath9k_tx_queue_info)); |
| 1347 | |
| 1348 | qi.tqi_aifs = params->aifs; |
| 1349 | qi.tqi_cwmin = params->cw_min; |
| 1350 | qi.tqi_cwmax = params->cw_max; |
| 1351 | qi.tqi_burstTime = params->txop; |
| 1352 | |
| 1353 | qnum = get_hw_qnum(queue, priv->hwq_map); |
| 1354 | |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 1355 | ath_dbg(common, ATH_DBG_CONFIG, |
| 1356 | "Configure tx [queue/hwq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n", |
| 1357 | queue, qnum, params->aifs, params->cw_min, |
| 1358 | params->cw_max, params->txop); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1359 | |
Sujith | e1572c5 | 2010-03-24 13:42:13 +0530 | [diff] [blame] | 1360 | ret = ath_htc_txq_update(priv, qnum, &qi); |
Sujith | 764580f | 2010-06-01 15:14:19 +0530 | [diff] [blame] | 1361 | if (ret) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 1362 | ath_err(common, "TXQ Update failed\n"); |
Sujith | 764580f | 2010-06-01 15:14:19 +0530 | [diff] [blame] | 1363 | goto out; |
| 1364 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1365 | |
Sujith | 764580f | 2010-06-01 15:14:19 +0530 | [diff] [blame] | 1366 | if ((priv->ah->opmode == NL80211_IFTYPE_ADHOC) && |
Felix Fietkau | e8c35a7 | 2010-06-12 00:33:50 -0400 | [diff] [blame] | 1367 | (qnum == priv->hwq_map[WME_AC_BE])) |
Sujith | 764580f | 2010-06-01 15:14:19 +0530 | [diff] [blame] | 1368 | ath9k_htc_beaconq_config(priv); |
| 1369 | out: |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1370 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1371 | mutex_unlock(&priv->mutex); |
| 1372 | |
| 1373 | return ret; |
| 1374 | } |
| 1375 | |
| 1376 | static int ath9k_htc_set_key(struct ieee80211_hw *hw, |
| 1377 | enum set_key_cmd cmd, |
| 1378 | struct ieee80211_vif *vif, |
| 1379 | struct ieee80211_sta *sta, |
| 1380 | struct ieee80211_key_conf *key) |
| 1381 | { |
| 1382 | struct ath9k_htc_priv *priv = hw->priv; |
| 1383 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 1384 | int ret = 0; |
| 1385 | |
Sujith | e1572c5 | 2010-03-24 13:42:13 +0530 | [diff] [blame] | 1386 | if (htc_modparam_nohwcrypt) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1387 | return -ENOSPC; |
| 1388 | |
| 1389 | mutex_lock(&priv->mutex); |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 1390 | ath_dbg(common, ATH_DBG_CONFIG, "Set HW Key\n"); |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1391 | ath9k_htc_ps_wakeup(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1392 | |
| 1393 | switch (cmd) { |
| 1394 | case SET_KEY: |
Bruno Randolf | 040e539 | 2010-09-08 16:05:04 +0900 | [diff] [blame] | 1395 | ret = ath_key_config(common, vif, sta, key); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1396 | if (ret >= 0) { |
| 1397 | key->hw_key_idx = ret; |
| 1398 | /* push IV and Michael MIC generation to stack */ |
| 1399 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 1400 | if (key->cipher == WLAN_CIPHER_SUITE_TKIP) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1401 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 1402 | if (priv->ah->sw_mgmt_crypto && |
| 1403 | key->cipher == WLAN_CIPHER_SUITE_CCMP) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1404 | key->flags |= IEEE80211_KEY_FLAG_SW_MGMT; |
| 1405 | ret = 0; |
| 1406 | } |
| 1407 | break; |
| 1408 | case DISABLE_KEY: |
Bruno Randolf | 040e539 | 2010-09-08 16:05:04 +0900 | [diff] [blame] | 1409 | ath_key_delete(common, key); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1410 | break; |
| 1411 | default: |
| 1412 | ret = -EINVAL; |
| 1413 | } |
| 1414 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1415 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1416 | mutex_unlock(&priv->mutex); |
| 1417 | |
| 1418 | return ret; |
| 1419 | } |
| 1420 | |
| 1421 | static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw, |
| 1422 | struct ieee80211_vif *vif, |
| 1423 | struct ieee80211_bss_conf *bss_conf, |
| 1424 | u32 changed) |
| 1425 | { |
| 1426 | struct ath9k_htc_priv *priv = hw->priv; |
| 1427 | struct ath_hw *ah = priv->ah; |
| 1428 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith Manoharan | e7a2a4f | 2011-02-27 09:20:40 +0530 | [diff] [blame] | 1429 | bool set_assoc; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1430 | |
| 1431 | mutex_lock(&priv->mutex); |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1432 | ath9k_htc_ps_wakeup(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1433 | |
Sujith Manoharan | e7a2a4f | 2011-02-27 09:20:40 +0530 | [diff] [blame] | 1434 | /* |
| 1435 | * Set the HW AID/BSSID only for the first station interface |
| 1436 | * or in IBSS mode. |
| 1437 | */ |
| 1438 | set_assoc = !!((priv->ah->opmode == NL80211_IFTYPE_ADHOC) || |
| 1439 | ((priv->ah->opmode == NL80211_IFTYPE_STATION) && |
| 1440 | (priv->num_sta_vif == 1))); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1441 | |
Sujith Manoharan | e7a2a4f | 2011-02-27 09:20:40 +0530 | [diff] [blame] | 1442 | |
| 1443 | if (changed & BSS_CHANGED_ASSOC) { |
| 1444 | if (set_assoc) { |
| 1445 | ath_dbg(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n", |
| 1446 | bss_conf->assoc); |
| 1447 | |
| 1448 | common->curaid = bss_conf->assoc ? |
| 1449 | bss_conf->aid : 0; |
| 1450 | |
| 1451 | if (bss_conf->assoc) |
| 1452 | ath9k_htc_start_ani(priv); |
| 1453 | else |
| 1454 | ath9k_htc_stop_ani(priv); |
| 1455 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1456 | } |
| 1457 | |
| 1458 | if (changed & BSS_CHANGED_BSSID) { |
Sujith Manoharan | e7a2a4f | 2011-02-27 09:20:40 +0530 | [diff] [blame] | 1459 | if (set_assoc) { |
| 1460 | memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN); |
| 1461 | ath9k_hw_write_associd(ah); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1462 | |
Sujith Manoharan | e7a2a4f | 2011-02-27 09:20:40 +0530 | [diff] [blame] | 1463 | ath_dbg(common, ATH_DBG_CONFIG, |
| 1464 | "BSSID: %pM aid: 0x%x\n", |
| 1465 | common->curbssid, common->curaid); |
| 1466 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1467 | } |
| 1468 | |
Sujith Manoharan | a5fae37 | 2011-02-21 07:49:53 +0530 | [diff] [blame] | 1469 | if ((changed & BSS_CHANGED_BEACON_ENABLED) && bss_conf->enable_beacon) { |
| 1470 | ath_dbg(common, ATH_DBG_CONFIG, |
| 1471 | "Beacon enabled for BSS: %pM\n", bss_conf->bssid); |
Sujith Manoharan | 9b674a0 | 2011-04-13 11:23:17 +0530 | [diff] [blame] | 1472 | ath9k_htc_set_tsfadjust(priv, vif); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1473 | priv->op_flags |= OP_ENABLE_BEACON; |
Vivek Natarajan | 1c3652a | 2010-04-05 14:48:06 +0530 | [diff] [blame] | 1474 | ath9k_htc_beacon_config(priv, vif); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1475 | } |
| 1476 | |
Sujith Manoharan | a5fae37 | 2011-02-21 07:49:53 +0530 | [diff] [blame] | 1477 | if ((changed & BSS_CHANGED_BEACON_ENABLED) && !bss_conf->enable_beacon) { |
| 1478 | /* |
| 1479 | * Disable SWBA interrupt only if there are no |
| 1480 | * AP/IBSS interfaces. |
| 1481 | */ |
| 1482 | if ((priv->num_ap_vif <= 1) || priv->num_ibss_vif) { |
| 1483 | ath_dbg(common, ATH_DBG_CONFIG, |
| 1484 | "Beacon disabled for BSS: %pM\n", |
| 1485 | bss_conf->bssid); |
| 1486 | priv->op_flags &= ~OP_ENABLE_BEACON; |
| 1487 | ath9k_htc_beacon_config(priv, vif); |
| 1488 | } |
| 1489 | } |
| 1490 | |
| 1491 | if (changed & BSS_CHANGED_BEACON_INT) { |
| 1492 | /* |
| 1493 | * Reset the HW TSF for the first AP interface. |
| 1494 | */ |
| 1495 | if ((priv->ah->opmode == NL80211_IFTYPE_AP) && |
| 1496 | (priv->nvifs == 1) && |
| 1497 | (priv->num_ap_vif == 1) && |
| 1498 | (vif->type == NL80211_IFTYPE_AP)) { |
| 1499 | priv->op_flags |= OP_TSF_RESET; |
| 1500 | } |
| 1501 | ath_dbg(common, ATH_DBG_CONFIG, |
| 1502 | "Beacon interval changed for BSS: %pM\n", |
| 1503 | bss_conf->bssid); |
Vivek Natarajan | 1c3652a | 2010-04-05 14:48:06 +0530 | [diff] [blame] | 1504 | ath9k_htc_beacon_config(priv, vif); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1505 | } |
| 1506 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1507 | if (changed & BSS_CHANGED_ERP_SLOT) { |
| 1508 | if (bss_conf->use_short_slot) |
| 1509 | ah->slottime = 9; |
| 1510 | else |
| 1511 | ah->slottime = 20; |
| 1512 | |
| 1513 | ath9k_hw_init_global_settings(ah); |
| 1514 | } |
| 1515 | |
Sujith | 2c76ef8 | 2010-05-17 12:01:18 +0530 | [diff] [blame] | 1516 | if (changed & BSS_CHANGED_HT) |
| 1517 | ath9k_htc_update_rate(priv, vif, bss_conf); |
| 1518 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1519 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1520 | mutex_unlock(&priv->mutex); |
| 1521 | } |
| 1522 | |
| 1523 | static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw) |
| 1524 | { |
| 1525 | struct ath9k_htc_priv *priv = hw->priv; |
| 1526 | u64 tsf; |
| 1527 | |
| 1528 | mutex_lock(&priv->mutex); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1529 | ath9k_htc_ps_wakeup(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1530 | tsf = ath9k_hw_gettsf64(priv->ah); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1531 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1532 | mutex_unlock(&priv->mutex); |
| 1533 | |
| 1534 | return tsf; |
| 1535 | } |
| 1536 | |
| 1537 | static void ath9k_htc_set_tsf(struct ieee80211_hw *hw, u64 tsf) |
| 1538 | { |
| 1539 | struct ath9k_htc_priv *priv = hw->priv; |
| 1540 | |
| 1541 | mutex_lock(&priv->mutex); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1542 | ath9k_htc_ps_wakeup(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1543 | ath9k_hw_settsf64(priv->ah, tsf); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1544 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1545 | mutex_unlock(&priv->mutex); |
| 1546 | } |
| 1547 | |
| 1548 | static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw) |
| 1549 | { |
| 1550 | struct ath9k_htc_priv *priv = hw->priv; |
| 1551 | |
| 1552 | mutex_lock(&priv->mutex); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1553 | ath9k_htc_ps_wakeup(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1554 | ath9k_hw_reset_tsf(priv->ah); |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1555 | ath9k_htc_ps_restore(priv); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1556 | mutex_unlock(&priv->mutex); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1557 | } |
| 1558 | |
| 1559 | static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw, |
| 1560 | struct ieee80211_vif *vif, |
| 1561 | enum ieee80211_ampdu_mlme_action action, |
| 1562 | struct ieee80211_sta *sta, |
Johannes Berg | 0b01f03 | 2011-01-18 13:51:05 +0100 | [diff] [blame] | 1563 | u16 tid, u16 *ssn, u8 buf_size) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1564 | { |
| 1565 | struct ath9k_htc_priv *priv = hw->priv; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1566 | struct ath9k_htc_sta *ista; |
Sujith | d7ca213 | 2010-06-15 10:24:37 +0530 | [diff] [blame] | 1567 | int ret = 0; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1568 | |
Sujith Manoharan | 87df895 | 2011-02-21 07:49:08 +0530 | [diff] [blame] | 1569 | mutex_lock(&priv->mutex); |
| 1570 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1571 | switch (action) { |
| 1572 | case IEEE80211_AMPDU_RX_START: |
| 1573 | break; |
| 1574 | case IEEE80211_AMPDU_RX_STOP: |
| 1575 | break; |
| 1576 | case IEEE80211_AMPDU_TX_START: |
Sujith | d7ca213 | 2010-06-15 10:24:37 +0530 | [diff] [blame] | 1577 | ret = ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid); |
| 1578 | if (!ret) |
| 1579 | ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 1580 | break; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1581 | case IEEE80211_AMPDU_TX_STOP: |
Sujith | d7ca213 | 2010-06-15 10:24:37 +0530 | [diff] [blame] | 1582 | ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid); |
| 1583 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1584 | break; |
| 1585 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
| 1586 | ista = (struct ath9k_htc_sta *) sta->drv_priv; |
Sujith Manoharan | 658ef04 | 2011-04-13 11:25:00 +0530 | [diff] [blame] | 1587 | spin_lock_bh(&priv->tx.tx_lock); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1588 | ista->tid_state[tid] = AGGR_OPERATIONAL; |
Sujith Manoharan | 658ef04 | 2011-04-13 11:25:00 +0530 | [diff] [blame] | 1589 | spin_unlock_bh(&priv->tx.tx_lock); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1590 | break; |
| 1591 | default: |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 1592 | ath_err(ath9k_hw_common(priv->ah), "Unknown AMPDU action\n"); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1593 | } |
| 1594 | |
Sujith Manoharan | 87df895 | 2011-02-21 07:49:08 +0530 | [diff] [blame] | 1595 | mutex_unlock(&priv->mutex); |
| 1596 | |
Sujith | d7ca213 | 2010-06-15 10:24:37 +0530 | [diff] [blame] | 1597 | return ret; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1598 | } |
| 1599 | |
| 1600 | static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw) |
| 1601 | { |
| 1602 | struct ath9k_htc_priv *priv = hw->priv; |
| 1603 | |
| 1604 | mutex_lock(&priv->mutex); |
| 1605 | spin_lock_bh(&priv->beacon_lock); |
| 1606 | priv->op_flags |= OP_SCANNING; |
| 1607 | spin_unlock_bh(&priv->beacon_lock); |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1608 | cancel_work_sync(&priv->ps_work); |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 1609 | ath9k_htc_stop_ani(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1610 | mutex_unlock(&priv->mutex); |
| 1611 | } |
| 1612 | |
| 1613 | static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw) |
| 1614 | { |
| 1615 | struct ath9k_htc_priv *priv = hw->priv; |
| 1616 | |
| 1617 | mutex_lock(&priv->mutex); |
| 1618 | spin_lock_bh(&priv->beacon_lock); |
| 1619 | priv->op_flags &= ~OP_SCANNING; |
| 1620 | spin_unlock_bh(&priv->beacon_lock); |
Sujith Manoharan | 7c27734 | 2011-02-21 07:48:39 +0530 | [diff] [blame] | 1621 | ath9k_htc_ps_wakeup(priv); |
| 1622 | ath9k_htc_vif_reconfig(priv); |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1623 | ath9k_htc_ps_restore(priv); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1624 | mutex_unlock(&priv->mutex); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1625 | } |
| 1626 | |
| 1627 | static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value) |
| 1628 | { |
| 1629 | return 0; |
| 1630 | } |
| 1631 | |
| 1632 | static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw, |
| 1633 | u8 coverage_class) |
| 1634 | { |
| 1635 | struct ath9k_htc_priv *priv = hw->priv; |
| 1636 | |
| 1637 | mutex_lock(&priv->mutex); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1638 | ath9k_htc_ps_wakeup(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1639 | priv->ah->coverage_class = coverage_class; |
| 1640 | ath9k_hw_init_global_settings(priv->ah); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1641 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1642 | mutex_unlock(&priv->mutex); |
| 1643 | } |
| 1644 | |
| 1645 | struct ieee80211_ops ath9k_htc_ops = { |
| 1646 | .tx = ath9k_htc_tx, |
| 1647 | .start = ath9k_htc_start, |
| 1648 | .stop = ath9k_htc_stop, |
| 1649 | .add_interface = ath9k_htc_add_interface, |
| 1650 | .remove_interface = ath9k_htc_remove_interface, |
| 1651 | .config = ath9k_htc_config, |
| 1652 | .configure_filter = ath9k_htc_configure_filter, |
Sujith | abd984e | 2010-05-18 15:26:04 +0530 | [diff] [blame] | 1653 | .sta_add = ath9k_htc_sta_add, |
| 1654 | .sta_remove = ath9k_htc_sta_remove, |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1655 | .conf_tx = ath9k_htc_conf_tx, |
| 1656 | .bss_info_changed = ath9k_htc_bss_info_changed, |
| 1657 | .set_key = ath9k_htc_set_key, |
| 1658 | .get_tsf = ath9k_htc_get_tsf, |
| 1659 | .set_tsf = ath9k_htc_set_tsf, |
| 1660 | .reset_tsf = ath9k_htc_reset_tsf, |
| 1661 | .ampdu_action = ath9k_htc_ampdu_action, |
| 1662 | .sw_scan_start = ath9k_htc_sw_scan_start, |
| 1663 | .sw_scan_complete = ath9k_htc_sw_scan_complete, |
| 1664 | .set_rts_threshold = ath9k_htc_set_rts_threshold, |
| 1665 | .rfkill_poll = ath9k_htc_rfkill_poll_state, |
| 1666 | .set_coverage_class = ath9k_htc_set_coverage_class, |
| 1667 | }; |