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