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 | |
| 19 | #ifdef CONFIG_ATH9K_HTC_DEBUGFS |
| 20 | static struct dentry *ath9k_debugfs_root; |
| 21 | #endif |
| 22 | |
| 23 | /*************/ |
| 24 | /* Utilities */ |
| 25 | /*************/ |
| 26 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 27 | /* HACK Alert: Use 11NG for 2.4, use 11NA for 5 */ |
| 28 | static enum htc_phymode ath9k_htc_get_curmode(struct ath9k_htc_priv *priv, |
| 29 | struct ath9k_channel *ichan) |
| 30 | { |
| 31 | enum htc_phymode mode; |
| 32 | |
| 33 | mode = HTC_MODE_AUTO; |
| 34 | |
| 35 | switch (ichan->chanmode) { |
| 36 | case CHANNEL_G: |
| 37 | case CHANNEL_G_HT20: |
| 38 | case CHANNEL_G_HT40PLUS: |
| 39 | case CHANNEL_G_HT40MINUS: |
| 40 | mode = HTC_MODE_11NG; |
| 41 | break; |
| 42 | case CHANNEL_A: |
| 43 | case CHANNEL_A_HT20: |
| 44 | case CHANNEL_A_HT40PLUS: |
| 45 | case CHANNEL_A_HT40MINUS: |
| 46 | mode = HTC_MODE_11NA; |
| 47 | break; |
| 48 | default: |
| 49 | break; |
| 50 | } |
| 51 | |
| 52 | return mode; |
| 53 | } |
| 54 | |
Sujith Manoharan | f933ebe | 2010-12-01 12:30:27 +0530 | [diff] [blame] | 55 | bool ath9k_htc_setpower(struct ath9k_htc_priv *priv, |
| 56 | enum ath9k_power_mode mode) |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 57 | { |
| 58 | bool ret; |
| 59 | |
| 60 | mutex_lock(&priv->htc_pm_lock); |
| 61 | ret = ath9k_hw_setpower(priv->ah, mode); |
| 62 | mutex_unlock(&priv->htc_pm_lock); |
| 63 | |
| 64 | return ret; |
| 65 | } |
| 66 | |
| 67 | void ath9k_htc_ps_wakeup(struct ath9k_htc_priv *priv) |
| 68 | { |
| 69 | mutex_lock(&priv->htc_pm_lock); |
| 70 | if (++priv->ps_usecount != 1) |
| 71 | goto unlock; |
| 72 | ath9k_hw_setpower(priv->ah, ATH9K_PM_AWAKE); |
| 73 | |
| 74 | unlock: |
| 75 | mutex_unlock(&priv->htc_pm_lock); |
| 76 | } |
| 77 | |
| 78 | void ath9k_htc_ps_restore(struct ath9k_htc_priv *priv) |
| 79 | { |
| 80 | mutex_lock(&priv->htc_pm_lock); |
| 81 | if (--priv->ps_usecount != 0) |
| 82 | goto unlock; |
| 83 | |
Vivek Natarajan | 8a8572a | 2010-04-27 13:05:37 +0530 | [diff] [blame] | 84 | if (priv->ps_idle) |
| 85 | ath9k_hw_setpower(priv->ah, ATH9K_PM_FULL_SLEEP); |
| 86 | else if (priv->ps_enabled) |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 87 | ath9k_hw_setpower(priv->ah, ATH9K_PM_NETWORK_SLEEP); |
Vivek Natarajan | 8a8572a | 2010-04-27 13:05:37 +0530 | [diff] [blame] | 88 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 89 | unlock: |
| 90 | mutex_unlock(&priv->htc_pm_lock); |
| 91 | } |
| 92 | |
| 93 | void ath9k_ps_work(struct work_struct *work) |
| 94 | { |
| 95 | struct ath9k_htc_priv *priv = |
| 96 | container_of(work, struct ath9k_htc_priv, |
| 97 | ps_work); |
| 98 | ath9k_htc_setpower(priv, ATH9K_PM_AWAKE); |
| 99 | |
| 100 | /* The chip wakes up after receiving the first beacon |
| 101 | while network sleep is enabled. For the driver to |
| 102 | be in sync with the hw, set the chip to awake and |
| 103 | only then set it to sleep. |
| 104 | */ |
| 105 | ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP); |
| 106 | } |
| 107 | |
Sujith Manoharan | 7c27734 | 2011-02-21 07:48:39 +0530 | [diff] [blame] | 108 | static void ath9k_htc_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif) |
| 109 | { |
| 110 | struct ath9k_htc_priv *priv = data; |
| 111 | struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; |
| 112 | |
Sujith Manoharan | a5fae37 | 2011-02-21 07:49:53 +0530 | [diff] [blame] | 113 | if ((vif->type == NL80211_IFTYPE_AP) && bss_conf->enable_beacon) |
| 114 | priv->reconfig_beacon = true; |
| 115 | |
Sujith Manoharan | 7c27734 | 2011-02-21 07:48:39 +0530 | [diff] [blame] | 116 | if (bss_conf->assoc) { |
| 117 | priv->rearm_ani = true; |
| 118 | priv->reconfig_beacon = true; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | static void ath9k_htc_vif_reconfig(struct ath9k_htc_priv *priv) |
| 123 | { |
| 124 | priv->rearm_ani = false; |
| 125 | priv->reconfig_beacon = false; |
| 126 | |
| 127 | ieee80211_iterate_active_interfaces_atomic(priv->hw, |
| 128 | ath9k_htc_vif_iter, priv); |
| 129 | if (priv->rearm_ani) |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 130 | ath9k_htc_start_ani(priv); |
Sujith Manoharan | 7c27734 | 2011-02-21 07:48:39 +0530 | [diff] [blame] | 131 | |
| 132 | if (priv->reconfig_beacon) { |
| 133 | ath9k_htc_ps_wakeup(priv); |
| 134 | ath9k_htc_beacon_reconfig(priv); |
| 135 | ath9k_htc_ps_restore(priv); |
| 136 | } |
| 137 | } |
| 138 | |
Sujith Manoharan | 585895c | 2011-02-21 07:48:46 +0530 | [diff] [blame] | 139 | static void ath9k_htc_bssid_iter(void *data, u8 *mac, struct ieee80211_vif *vif) |
| 140 | { |
| 141 | struct ath9k_vif_iter_data *iter_data = data; |
| 142 | int i; |
| 143 | |
| 144 | for (i = 0; i < ETH_ALEN; i++) |
| 145 | iter_data->mask[i] &= ~(iter_data->hw_macaddr[i] ^ mac[i]); |
| 146 | } |
| 147 | |
| 148 | static void ath9k_htc_set_bssid_mask(struct ath9k_htc_priv *priv, |
| 149 | struct ieee80211_vif *vif) |
| 150 | { |
| 151 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 152 | struct ath9k_vif_iter_data iter_data; |
| 153 | |
| 154 | /* |
| 155 | * Use the hardware MAC address as reference, the hardware uses it |
| 156 | * together with the BSSID mask when matching addresses. |
| 157 | */ |
| 158 | iter_data.hw_macaddr = common->macaddr; |
| 159 | memset(&iter_data.mask, 0xff, ETH_ALEN); |
| 160 | |
| 161 | if (vif) |
| 162 | ath9k_htc_bssid_iter(&iter_data, vif->addr, vif); |
| 163 | |
| 164 | /* Get list of all active MAC addresses */ |
| 165 | ieee80211_iterate_active_interfaces_atomic(priv->hw, ath9k_htc_bssid_iter, |
| 166 | &iter_data); |
| 167 | |
| 168 | memcpy(common->bssidmask, iter_data.mask, ETH_ALEN); |
| 169 | ath_hw_setbssidmask(common); |
| 170 | } |
| 171 | |
Sujith Manoharan | ffbe7c8 | 2011-02-21 07:49:31 +0530 | [diff] [blame] | 172 | static void ath9k_htc_set_opmode(struct ath9k_htc_priv *priv) |
| 173 | { |
| 174 | if (priv->num_ibss_vif) |
| 175 | priv->ah->opmode = NL80211_IFTYPE_ADHOC; |
| 176 | else if (priv->num_ap_vif) |
| 177 | priv->ah->opmode = NL80211_IFTYPE_AP; |
| 178 | else |
| 179 | priv->ah->opmode = NL80211_IFTYPE_STATION; |
| 180 | |
| 181 | ath9k_hw_setopmode(priv->ah); |
| 182 | } |
| 183 | |
Sujith Manoharan | 7390867 | 2010-12-28 14:28:27 +0530 | [diff] [blame] | 184 | void ath9k_htc_reset(struct ath9k_htc_priv *priv) |
| 185 | { |
| 186 | struct ath_hw *ah = priv->ah; |
| 187 | struct ath_common *common = ath9k_hw_common(ah); |
| 188 | struct ieee80211_channel *channel = priv->hw->conf.channel; |
Rajkumar Manoharan | 4e3ae38 | 2011-01-15 01:33:28 +0530 | [diff] [blame] | 189 | struct ath9k_hw_cal_data *caldata = NULL; |
Sujith Manoharan | 7390867 | 2010-12-28 14:28:27 +0530 | [diff] [blame] | 190 | enum htc_phymode mode; |
| 191 | __be16 htc_mode; |
| 192 | u8 cmd_rsp; |
| 193 | int ret; |
| 194 | |
| 195 | mutex_lock(&priv->mutex); |
| 196 | ath9k_htc_ps_wakeup(priv); |
| 197 | |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 198 | ath9k_htc_stop_ani(priv); |
Sujith Manoharan | 7390867 | 2010-12-28 14:28:27 +0530 | [diff] [blame] | 199 | ieee80211_stop_queues(priv->hw); |
| 200 | htc_stop(priv->htc); |
| 201 | WMI_CMD(WMI_DISABLE_INTR_CMDID); |
| 202 | WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID); |
| 203 | WMI_CMD(WMI_STOP_RECV_CMDID); |
| 204 | |
Rajkumar Manoharan | 4e3ae38 | 2011-01-15 01:33:28 +0530 | [diff] [blame] | 205 | caldata = &priv->caldata; |
Sujith Manoharan | 7390867 | 2010-12-28 14:28:27 +0530 | [diff] [blame] | 206 | ret = ath9k_hw_reset(ah, ah->curchan, caldata, false); |
| 207 | if (ret) { |
| 208 | ath_err(common, |
| 209 | "Unable to reset device (%u Mhz) reset status %d\n", |
| 210 | channel->center_freq, ret); |
| 211 | } |
| 212 | |
Rajkumar Manoharan | b2a5c3d | 2011-01-31 23:47:45 +0530 | [diff] [blame] | 213 | ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit, |
| 214 | &priv->curtxpow); |
Sujith Manoharan | 7390867 | 2010-12-28 14:28:27 +0530 | [diff] [blame] | 215 | |
| 216 | WMI_CMD(WMI_START_RECV_CMDID); |
| 217 | ath9k_host_rx_init(priv); |
| 218 | |
| 219 | mode = ath9k_htc_get_curmode(priv, ah->curchan); |
| 220 | htc_mode = cpu_to_be16(mode); |
| 221 | WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode); |
| 222 | |
| 223 | WMI_CMD(WMI_ENABLE_INTR_CMDID); |
| 224 | htc_start(priv->htc); |
Sujith Manoharan | 7c27734 | 2011-02-21 07:48:39 +0530 | [diff] [blame] | 225 | ath9k_htc_vif_reconfig(priv); |
Sujith Manoharan | 7390867 | 2010-12-28 14:28:27 +0530 | [diff] [blame] | 226 | ieee80211_wake_queues(priv->hw); |
| 227 | |
| 228 | ath9k_htc_ps_restore(priv); |
| 229 | mutex_unlock(&priv->mutex); |
| 230 | } |
| 231 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 232 | static int ath9k_htc_set_channel(struct ath9k_htc_priv *priv, |
| 233 | struct ieee80211_hw *hw, |
| 234 | struct ath9k_channel *hchan) |
| 235 | { |
| 236 | struct ath_hw *ah = priv->ah; |
| 237 | struct ath_common *common = ath9k_hw_common(ah); |
| 238 | struct ieee80211_conf *conf = &common->hw->conf; |
Sujith Manoharan | 039a072 | 2010-12-28 14:28:37 +0530 | [diff] [blame] | 239 | bool fastcc; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 240 | struct ieee80211_channel *channel = hw->conf.channel; |
Vivek Natarajan | 8354dd3 | 2011-02-18 16:09:51 +0530 | [diff] [blame] | 241 | struct ath9k_hw_cal_data *caldata = NULL; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 242 | enum htc_phymode mode; |
Sujith | 7f1f5a0 | 2010-04-16 11:54:03 +0530 | [diff] [blame] | 243 | __be16 htc_mode; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 244 | u8 cmd_rsp; |
| 245 | int ret; |
| 246 | |
| 247 | if (priv->op_flags & OP_INVALID) |
| 248 | return -EIO; |
| 249 | |
Sujith Manoharan | 039a072 | 2010-12-28 14:28:37 +0530 | [diff] [blame] | 250 | fastcc = !!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 251 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 252 | ath9k_htc_ps_wakeup(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 253 | htc_stop(priv->htc); |
| 254 | WMI_CMD(WMI_DISABLE_INTR_CMDID); |
| 255 | WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID); |
| 256 | WMI_CMD(WMI_STOP_RECV_CMDID); |
| 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 | |
| 352 | hvif.opmode = cpu_to_be32(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; |
| 385 | tsta.maxampdu = 0xffff; |
| 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); |
| 466 | tsta.associd = common->curaid; |
| 467 | tsta.is_vif_sta = 0; |
| 468 | tsta.valid = true; |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 469 | ista->index = sta_idx; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 470 | } else { |
| 471 | memcpy(&tsta.macaddr, vif->addr, ETH_ALEN); |
| 472 | tsta.is_vif_sta = 1; |
| 473 | } |
| 474 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 475 | tsta.sta_index = sta_idx; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 476 | tsta.vif_index = avp->index; |
| 477 | tsta.maxampdu = 0xffff; |
| 478 | if (sta && sta->ht_cap.ht_supported) |
| 479 | tsta.flags = cpu_to_be16(ATH_HTC_STA_HT); |
| 480 | |
| 481 | WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta); |
| 482 | if (ret) { |
| 483 | if (sta) |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 484 | ath_err(common, |
| 485 | "Unable to add station entry for: %pM\n", |
| 486 | sta->addr); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 487 | return ret; |
| 488 | } |
| 489 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 490 | if (sta) { |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 491 | ath_dbg(common, ATH_DBG_CONFIG, |
| 492 | "Added a station entry for: %pM (idx: %d)\n", |
| 493 | sta->addr, tsta.sta_index); |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 494 | } else { |
| 495 | ath_dbg(common, ATH_DBG_CONFIG, |
| 496 | "Added a station entry for VIF %d (idx: %d)\n", |
| 497 | avp->index, tsta.sta_index); |
| 498 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 499 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 500 | priv->sta_slot |= (1 << sta_idx); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 501 | priv->nstations++; |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 502 | if (!sta) |
| 503 | priv->vif_sta_pos[avp->index] = sta_idx; |
| 504 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 505 | return 0; |
| 506 | } |
| 507 | |
| 508 | static int ath9k_htc_remove_station(struct ath9k_htc_priv *priv, |
| 509 | struct ieee80211_vif *vif, |
| 510 | struct ieee80211_sta *sta) |
| 511 | { |
| 512 | struct ath_common *common = ath9k_hw_common(priv->ah); |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 513 | struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 514 | struct ath9k_htc_sta *ista; |
| 515 | int ret; |
| 516 | u8 cmd_rsp, sta_idx; |
| 517 | |
| 518 | if (sta) { |
| 519 | ista = (struct ath9k_htc_sta *) sta->drv_priv; |
| 520 | sta_idx = ista->index; |
| 521 | } else { |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 522 | sta_idx = priv->vif_sta_pos[avp->index]; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx); |
| 526 | if (ret) { |
| 527 | if (sta) |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 528 | ath_err(common, |
| 529 | "Unable to remove station entry for: %pM\n", |
| 530 | sta->addr); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 531 | return ret; |
| 532 | } |
| 533 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 534 | if (sta) { |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 535 | ath_dbg(common, ATH_DBG_CONFIG, |
| 536 | "Removed a station entry for: %pM (idx: %d)\n", |
| 537 | sta->addr, sta_idx); |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 538 | } else { |
| 539 | ath_dbg(common, ATH_DBG_CONFIG, |
| 540 | "Removed a station entry for VIF %d (idx: %d)\n", |
| 541 | avp->index, sta_idx); |
| 542 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 543 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 544 | priv->sta_slot &= ~(1 << sta_idx); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 545 | priv->nstations--; |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 546 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 547 | return 0; |
| 548 | } |
| 549 | |
Sujith Manoharan | 55de80d | 2011-01-05 01:06:21 +0530 | [diff] [blame] | 550 | int ath9k_htc_update_cap_target(struct ath9k_htc_priv *priv) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 551 | { |
| 552 | struct ath9k_htc_cap_target tcap; |
| 553 | int ret; |
| 554 | u8 cmd_rsp; |
| 555 | |
| 556 | memset(&tcap, 0, sizeof(struct ath9k_htc_cap_target)); |
| 557 | |
| 558 | /* FIXME: Values are hardcoded */ |
| 559 | tcap.flags = 0x240c40; |
| 560 | tcap.flags_ext = 0x80601000; |
| 561 | tcap.ampdu_limit = 0xffff0000; |
| 562 | tcap.ampdu_subframes = 20; |
Sujith | 29d9075 | 2010-06-02 15:53:43 +0530 | [diff] [blame] | 563 | tcap.tx_chainmask_legacy = priv->ah->caps.tx_chainmask; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 564 | tcap.protmode = 1; |
Sujith | 29d9075 | 2010-06-02 15:53:43 +0530 | [diff] [blame] | 565 | tcap.tx_chainmask = priv->ah->caps.tx_chainmask; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 566 | |
| 567 | WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID, &tcap); |
| 568 | |
| 569 | return ret; |
| 570 | } |
| 571 | |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 572 | static void ath9k_htc_setup_rate(struct ath9k_htc_priv *priv, |
| 573 | struct ieee80211_sta *sta, |
| 574 | struct ath9k_htc_target_rate *trate) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 575 | { |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 576 | struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv; |
| 577 | struct ieee80211_supported_band *sband; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 578 | u32 caps = 0; |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 579 | int i, j; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 580 | |
Sujith | ea46e64 | 2010-06-02 15:53:50 +0530 | [diff] [blame] | 581 | sband = priv->hw->wiphy->bands[priv->hw->conf.channel->band]; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 582 | |
| 583 | for (i = 0, j = 0; i < sband->n_bitrates; i++) { |
| 584 | if (sta->supp_rates[sband->band] & BIT(i)) { |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 585 | trate->rates.legacy_rates.rs_rates[j] |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 586 | = (sband->bitrates[i].bitrate * 2) / 10; |
| 587 | j++; |
| 588 | } |
| 589 | } |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 590 | trate->rates.legacy_rates.rs_nrates = j; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 591 | |
| 592 | if (sta->ht_cap.ht_supported) { |
| 593 | for (i = 0, j = 0; i < 77; i++) { |
| 594 | if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8))) |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 595 | trate->rates.ht_rates.rs_rates[j++] = i; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 596 | if (j == ATH_HTC_RATE_MAX) |
| 597 | break; |
| 598 | } |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 599 | trate->rates.ht_rates.rs_nrates = j; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 600 | |
| 601 | caps = WLAN_RC_HT_FLAG; |
Felix Fietkau | 3553727 | 2010-06-12 17:22:33 +0200 | [diff] [blame] | 602 | if (sta->ht_cap.mcs.rx_mask[1]) |
| 603 | caps |= WLAN_RC_DS_FLAG; |
Vivek Natarajan | 71ba186 | 2010-08-12 14:23:28 +0530 | [diff] [blame] | 604 | if ((sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) && |
| 605 | (conf_is_ht40(&priv->hw->conf))) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 606 | caps |= WLAN_RC_40_FLAG; |
Sujith | b4dec5e | 2010-05-17 12:01:19 +0530 | [diff] [blame] | 607 | if (conf_is_ht40(&priv->hw->conf) && |
| 608 | (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40)) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 609 | caps |= WLAN_RC_SGI_FLAG; |
Sujith | b4dec5e | 2010-05-17 12:01:19 +0530 | [diff] [blame] | 610 | else if (conf_is_ht20(&priv->hw->conf) && |
| 611 | (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20)) |
| 612 | caps |= WLAN_RC_SGI_FLAG; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 613 | } |
| 614 | |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 615 | trate->sta_index = ista->index; |
| 616 | trate->isnew = 1; |
| 617 | trate->capflags = cpu_to_be32(caps); |
| 618 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 619 | |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 620 | static int ath9k_htc_send_rate_cmd(struct ath9k_htc_priv *priv, |
| 621 | struct ath9k_htc_target_rate *trate) |
| 622 | { |
| 623 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 624 | int ret; |
| 625 | u8 cmd_rsp; |
| 626 | |
| 627 | WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID, trate); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 628 | if (ret) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 629 | ath_err(common, |
| 630 | "Unable to initialize Rate information on target\n"); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 631 | } |
| 632 | |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 633 | return ret; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 634 | } |
| 635 | |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 636 | static void ath9k_htc_init_rate(struct ath9k_htc_priv *priv, |
| 637 | struct ieee80211_sta *sta) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 638 | { |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 639 | struct ath_common *common = ath9k_hw_common(priv->ah); |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 640 | struct ath9k_htc_target_rate trate; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 641 | int ret; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 642 | |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 643 | memset(&trate, 0, sizeof(struct ath9k_htc_target_rate)); |
| 644 | ath9k_htc_setup_rate(priv, sta, &trate); |
| 645 | ret = ath9k_htc_send_rate_cmd(priv, &trate); |
| 646 | if (!ret) |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 647 | ath_dbg(common, ATH_DBG_CONFIG, |
| 648 | "Updated target sta: %pM, rate caps: 0x%X\n", |
| 649 | sta->addr, be32_to_cpu(trate.capflags)); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 650 | } |
| 651 | |
Sujith | 2c76ef8 | 2010-05-17 12:01:18 +0530 | [diff] [blame] | 652 | static void ath9k_htc_update_rate(struct ath9k_htc_priv *priv, |
| 653 | struct ieee80211_vif *vif, |
| 654 | struct ieee80211_bss_conf *bss_conf) |
| 655 | { |
| 656 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 657 | struct ath9k_htc_target_rate trate; |
| 658 | struct ieee80211_sta *sta; |
| 659 | int ret; |
| 660 | |
| 661 | memset(&trate, 0, sizeof(struct ath9k_htc_target_rate)); |
| 662 | |
| 663 | rcu_read_lock(); |
| 664 | sta = ieee80211_find_sta(vif, bss_conf->bssid); |
| 665 | if (!sta) { |
| 666 | rcu_read_unlock(); |
| 667 | return; |
| 668 | } |
| 669 | ath9k_htc_setup_rate(priv, sta, &trate); |
| 670 | rcu_read_unlock(); |
| 671 | |
| 672 | ret = ath9k_htc_send_rate_cmd(priv, &trate); |
| 673 | if (!ret) |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 674 | ath_dbg(common, ATH_DBG_CONFIG, |
| 675 | "Updated target sta: %pM, rate caps: 0x%X\n", |
| 676 | bss_conf->bssid, be32_to_cpu(trate.capflags)); |
Sujith | 2c76ef8 | 2010-05-17 12:01:18 +0530 | [diff] [blame] | 677 | } |
| 678 | |
Luis R. Rodriguez | 9edd952 | 2010-07-13 21:27:25 -0400 | [diff] [blame] | 679 | static int ath9k_htc_tx_aggr_oper(struct ath9k_htc_priv *priv, |
| 680 | struct ieee80211_vif *vif, |
| 681 | struct ieee80211_sta *sta, |
| 682 | enum ieee80211_ampdu_mlme_action action, |
| 683 | u16 tid) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 684 | { |
| 685 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 686 | struct ath9k_htc_target_aggr aggr; |
Dan Carpenter | 277a64d | 2010-05-08 18:23:20 +0200 | [diff] [blame] | 687 | struct ath9k_htc_sta *ista; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 688 | int ret = 0; |
| 689 | u8 cmd_rsp; |
| 690 | |
Dan Carpenter | 0730d11 | 2010-05-08 18:24:02 +0200 | [diff] [blame] | 691 | if (tid >= ATH9K_HTC_MAX_TID) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 692 | return -EINVAL; |
| 693 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 694 | memset(&aggr, 0, sizeof(struct ath9k_htc_target_aggr)); |
Sujith | ef98c3c | 2010-03-29 16:07:11 +0530 | [diff] [blame] | 695 | ista = (struct ath9k_htc_sta *) sta->drv_priv; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 696 | |
Sujith | ef98c3c | 2010-03-29 16:07:11 +0530 | [diff] [blame] | 697 | aggr.sta_index = ista->index; |
Sujith | d7ca213 | 2010-06-15 10:24:37 +0530 | [diff] [blame] | 698 | aggr.tidno = tid & 0xf; |
| 699 | aggr.aggr_enable = (action == IEEE80211_AMPDU_TX_START) ? true : false; |
Sujith | ef98c3c | 2010-03-29 16:07:11 +0530 | [diff] [blame] | 700 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 701 | WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID, &aggr); |
| 702 | if (ret) |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 703 | ath_dbg(common, ATH_DBG_CONFIG, |
| 704 | "Unable to %s TX aggregation for (%pM, %d)\n", |
| 705 | (aggr.aggr_enable) ? "start" : "stop", sta->addr, tid); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 706 | else |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 707 | ath_dbg(common, ATH_DBG_CONFIG, |
| 708 | "%s TX aggregation for (%pM, %d)\n", |
| 709 | (aggr.aggr_enable) ? "Starting" : "Stopping", |
| 710 | sta->addr, tid); |
Sujith | d7ca213 | 2010-06-15 10:24:37 +0530 | [diff] [blame] | 711 | |
| 712 | spin_lock_bh(&priv->tx_lock); |
| 713 | ista->tid_state[tid] = (aggr.aggr_enable && !ret) ? AGGR_START : AGGR_STOP; |
| 714 | spin_unlock_bh(&priv->tx_lock); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 715 | |
| 716 | return ret; |
| 717 | } |
| 718 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 719 | /*********/ |
| 720 | /* DEBUG */ |
| 721 | /*********/ |
| 722 | |
| 723 | #ifdef CONFIG_ATH9K_HTC_DEBUGFS |
| 724 | |
| 725 | static int ath9k_debugfs_open(struct inode *inode, struct file *file) |
| 726 | { |
| 727 | file->private_data = inode->i_private; |
| 728 | return 0; |
| 729 | } |
| 730 | |
| 731 | static ssize_t read_file_tgt_stats(struct file *file, char __user *user_buf, |
| 732 | size_t count, loff_t *ppos) |
| 733 | { |
Joe Perches | 5767430 | 2010-07-12 13:50:06 -0700 | [diff] [blame] | 734 | struct ath9k_htc_priv *priv = file->private_data; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 735 | struct ath9k_htc_target_stats cmd_rsp; |
| 736 | char buf[512]; |
| 737 | unsigned int len = 0; |
| 738 | int ret = 0; |
| 739 | |
| 740 | memset(&cmd_rsp, 0, sizeof(cmd_rsp)); |
| 741 | |
| 742 | WMI_CMD(WMI_TGT_STATS_CMDID); |
| 743 | if (ret) |
| 744 | return -EINVAL; |
| 745 | |
| 746 | |
| 747 | len += snprintf(buf + len, sizeof(buf) - len, |
| 748 | "%19s : %10u\n", "TX Short Retries", |
| 749 | be32_to_cpu(cmd_rsp.tx_shortretry)); |
| 750 | len += snprintf(buf + len, sizeof(buf) - len, |
| 751 | "%19s : %10u\n", "TX Long Retries", |
| 752 | be32_to_cpu(cmd_rsp.tx_longretry)); |
| 753 | len += snprintf(buf + len, sizeof(buf) - len, |
| 754 | "%19s : %10u\n", "TX Xretries", |
| 755 | be32_to_cpu(cmd_rsp.tx_xretries)); |
| 756 | len += snprintf(buf + len, sizeof(buf) - len, |
| 757 | "%19s : %10u\n", "TX Unaggr. Xretries", |
| 758 | be32_to_cpu(cmd_rsp.ht_txunaggr_xretry)); |
| 759 | len += snprintf(buf + len, sizeof(buf) - len, |
| 760 | "%19s : %10u\n", "TX Xretries (HT)", |
| 761 | be32_to_cpu(cmd_rsp.ht_tx_xretries)); |
| 762 | len += snprintf(buf + len, sizeof(buf) - len, |
| 763 | "%19s : %10u\n", "TX Rate", priv->debug.txrate); |
| 764 | |
Dan Carpenter | 9746010 | 2010-07-22 10:50:28 +0200 | [diff] [blame] | 765 | if (len > sizeof(buf)) |
| 766 | len = sizeof(buf); |
| 767 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 768 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 769 | } |
| 770 | |
| 771 | static const struct file_operations fops_tgt_stats = { |
| 772 | .read = read_file_tgt_stats, |
| 773 | .open = ath9k_debugfs_open, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 774 | .owner = THIS_MODULE, |
| 775 | .llseek = default_llseek, |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 776 | }; |
| 777 | |
| 778 | static ssize_t read_file_xmit(struct file *file, char __user *user_buf, |
| 779 | size_t count, loff_t *ppos) |
| 780 | { |
Joe Perches | 5767430 | 2010-07-12 13:50:06 -0700 | [diff] [blame] | 781 | struct ath9k_htc_priv *priv = file->private_data; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 782 | char buf[512]; |
| 783 | unsigned int len = 0; |
| 784 | |
| 785 | len += snprintf(buf + len, sizeof(buf) - len, |
| 786 | "%20s : %10u\n", "Buffers queued", |
| 787 | priv->debug.tx_stats.buf_queued); |
| 788 | len += snprintf(buf + len, sizeof(buf) - len, |
| 789 | "%20s : %10u\n", "Buffers completed", |
| 790 | priv->debug.tx_stats.buf_completed); |
| 791 | len += snprintf(buf + len, sizeof(buf) - len, |
| 792 | "%20s : %10u\n", "SKBs queued", |
| 793 | priv->debug.tx_stats.skb_queued); |
| 794 | len += snprintf(buf + len, sizeof(buf) - len, |
| 795 | "%20s : %10u\n", "SKBs completed", |
| 796 | priv->debug.tx_stats.skb_completed); |
Sujith | eac8e38 | 2010-04-16 11:54:00 +0530 | [diff] [blame] | 797 | len += snprintf(buf + len, sizeof(buf) - len, |
| 798 | "%20s : %10u\n", "SKBs dropped", |
| 799 | priv->debug.tx_stats.skb_dropped); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 800 | |
Sujith | 2edb458 | 2010-05-14 11:18:54 +0530 | [diff] [blame] | 801 | len += snprintf(buf + len, sizeof(buf) - len, |
| 802 | "%20s : %10u\n", "BE queued", |
| 803 | priv->debug.tx_stats.queue_stats[WME_AC_BE]); |
| 804 | len += snprintf(buf + len, sizeof(buf) - len, |
| 805 | "%20s : %10u\n", "BK queued", |
| 806 | priv->debug.tx_stats.queue_stats[WME_AC_BK]); |
| 807 | len += snprintf(buf + len, sizeof(buf) - len, |
| 808 | "%20s : %10u\n", "VI queued", |
| 809 | priv->debug.tx_stats.queue_stats[WME_AC_VI]); |
| 810 | len += snprintf(buf + len, sizeof(buf) - len, |
| 811 | "%20s : %10u\n", "VO queued", |
| 812 | priv->debug.tx_stats.queue_stats[WME_AC_VO]); |
| 813 | |
Dan Carpenter | 9746010 | 2010-07-22 10:50:28 +0200 | [diff] [blame] | 814 | if (len > sizeof(buf)) |
| 815 | len = sizeof(buf); |
| 816 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 817 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 818 | } |
| 819 | |
| 820 | static const struct file_operations fops_xmit = { |
| 821 | .read = read_file_xmit, |
| 822 | .open = ath9k_debugfs_open, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 823 | .owner = THIS_MODULE, |
| 824 | .llseek = default_llseek, |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 825 | }; |
| 826 | |
| 827 | static ssize_t read_file_recv(struct file *file, char __user *user_buf, |
| 828 | size_t count, loff_t *ppos) |
| 829 | { |
Joe Perches | 5767430 | 2010-07-12 13:50:06 -0700 | [diff] [blame] | 830 | struct ath9k_htc_priv *priv = file->private_data; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 831 | char buf[512]; |
| 832 | unsigned int len = 0; |
| 833 | |
| 834 | len += snprintf(buf + len, sizeof(buf) - len, |
| 835 | "%20s : %10u\n", "SKBs allocated", |
| 836 | priv->debug.rx_stats.skb_allocated); |
| 837 | len += snprintf(buf + len, sizeof(buf) - len, |
| 838 | "%20s : %10u\n", "SKBs completed", |
| 839 | priv->debug.rx_stats.skb_completed); |
| 840 | len += snprintf(buf + len, sizeof(buf) - len, |
| 841 | "%20s : %10u\n", "SKBs Dropped", |
| 842 | priv->debug.rx_stats.skb_dropped); |
| 843 | |
Dan Carpenter | 9746010 | 2010-07-22 10:50:28 +0200 | [diff] [blame] | 844 | if (len > sizeof(buf)) |
| 845 | len = sizeof(buf); |
| 846 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 847 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 848 | } |
| 849 | |
| 850 | static const struct file_operations fops_recv = { |
| 851 | .read = read_file_recv, |
| 852 | .open = ath9k_debugfs_open, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 853 | .owner = THIS_MODULE, |
| 854 | .llseek = default_llseek, |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 855 | }; |
| 856 | |
Sujith | e1572c5 | 2010-03-24 13:42:13 +0530 | [diff] [blame] | 857 | int ath9k_htc_init_debug(struct ath_hw *ah) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 858 | { |
| 859 | struct ath_common *common = ath9k_hw_common(ah); |
| 860 | struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv; |
| 861 | |
| 862 | if (!ath9k_debugfs_root) |
| 863 | return -ENOENT; |
| 864 | |
| 865 | priv->debug.debugfs_phy = debugfs_create_dir(wiphy_name(priv->hw->wiphy), |
| 866 | ath9k_debugfs_root); |
| 867 | if (!priv->debug.debugfs_phy) |
| 868 | goto err; |
| 869 | |
| 870 | priv->debug.debugfs_tgt_stats = debugfs_create_file("tgt_stats", S_IRUSR, |
| 871 | priv->debug.debugfs_phy, |
| 872 | priv, &fops_tgt_stats); |
| 873 | if (!priv->debug.debugfs_tgt_stats) |
| 874 | goto err; |
| 875 | |
| 876 | |
| 877 | priv->debug.debugfs_xmit = debugfs_create_file("xmit", S_IRUSR, |
| 878 | priv->debug.debugfs_phy, |
| 879 | priv, &fops_xmit); |
| 880 | if (!priv->debug.debugfs_xmit) |
| 881 | goto err; |
| 882 | |
| 883 | priv->debug.debugfs_recv = debugfs_create_file("recv", S_IRUSR, |
| 884 | priv->debug.debugfs_phy, |
| 885 | priv, &fops_recv); |
| 886 | if (!priv->debug.debugfs_recv) |
| 887 | goto err; |
| 888 | |
| 889 | return 0; |
| 890 | |
| 891 | err: |
Sujith | e1572c5 | 2010-03-24 13:42:13 +0530 | [diff] [blame] | 892 | ath9k_htc_exit_debug(ah); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 893 | return -ENOMEM; |
| 894 | } |
| 895 | |
Sujith | e1572c5 | 2010-03-24 13:42:13 +0530 | [diff] [blame] | 896 | void ath9k_htc_exit_debug(struct ath_hw *ah) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 897 | { |
| 898 | struct ath_common *common = ath9k_hw_common(ah); |
| 899 | struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv; |
| 900 | |
| 901 | debugfs_remove(priv->debug.debugfs_recv); |
| 902 | debugfs_remove(priv->debug.debugfs_xmit); |
| 903 | debugfs_remove(priv->debug.debugfs_tgt_stats); |
| 904 | debugfs_remove(priv->debug.debugfs_phy); |
| 905 | } |
| 906 | |
Sujith | e1572c5 | 2010-03-24 13:42:13 +0530 | [diff] [blame] | 907 | int ath9k_htc_debug_create_root(void) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 908 | { |
| 909 | ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL); |
| 910 | if (!ath9k_debugfs_root) |
| 911 | return -ENOENT; |
| 912 | |
| 913 | return 0; |
| 914 | } |
| 915 | |
Sujith | e1572c5 | 2010-03-24 13:42:13 +0530 | [diff] [blame] | 916 | void ath9k_htc_debug_remove_root(void) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 917 | { |
| 918 | debugfs_remove(ath9k_debugfs_root); |
| 919 | ath9k_debugfs_root = NULL; |
| 920 | } |
| 921 | |
| 922 | #endif /* CONFIG_ATH9K_HTC_DEBUGFS */ |
| 923 | |
| 924 | /*******/ |
| 925 | /* ANI */ |
| 926 | /*******/ |
| 927 | |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 928 | void ath9k_htc_start_ani(struct ath9k_htc_priv *priv) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 929 | { |
| 930 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 931 | unsigned long timestamp = jiffies_to_msecs(jiffies); |
| 932 | |
| 933 | common->ani.longcal_timer = timestamp; |
| 934 | common->ani.shortcal_timer = timestamp; |
| 935 | common->ani.checkani_timer = timestamp; |
| 936 | |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 937 | priv->op_flags |= OP_ANI_RUNNING; |
| 938 | |
| 939 | ieee80211_queue_delayed_work(common->hw, &priv->ani_work, |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 940 | msecs_to_jiffies(ATH_ANI_POLLINTERVAL)); |
| 941 | } |
| 942 | |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 943 | void ath9k_htc_stop_ani(struct ath9k_htc_priv *priv) |
| 944 | { |
| 945 | cancel_delayed_work_sync(&priv->ani_work); |
| 946 | priv->op_flags &= ~OP_ANI_RUNNING; |
| 947 | } |
| 948 | |
| 949 | void ath9k_htc_ani_work(struct work_struct *work) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 950 | { |
| 951 | struct ath9k_htc_priv *priv = |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 952 | container_of(work, struct ath9k_htc_priv, ani_work.work); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 953 | struct ath_hw *ah = priv->ah; |
| 954 | struct ath_common *common = ath9k_hw_common(ah); |
| 955 | bool longcal = false; |
| 956 | bool shortcal = false; |
| 957 | bool aniflag = false; |
| 958 | unsigned int timestamp = jiffies_to_msecs(jiffies); |
| 959 | u32 cal_interval, short_cal_interval; |
| 960 | |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 961 | short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ? |
| 962 | ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 963 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 964 | /* Only calibrate if awake */ |
| 965 | if (ah->power_mode != ATH9K_PM_AWAKE) |
| 966 | goto set_timer; |
| 967 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 968 | /* Long calibration runs independently of short calibration. */ |
| 969 | if ((timestamp - common->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) { |
| 970 | longcal = true; |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 971 | ath_dbg(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 972 | common->ani.longcal_timer = timestamp; |
| 973 | } |
| 974 | |
| 975 | /* Short calibration applies only while caldone is false */ |
| 976 | if (!common->ani.caldone) { |
| 977 | if ((timestamp - common->ani.shortcal_timer) >= |
| 978 | short_cal_interval) { |
| 979 | shortcal = true; |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 980 | ath_dbg(common, ATH_DBG_ANI, |
| 981 | "shortcal @%lu\n", jiffies); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 982 | common->ani.shortcal_timer = timestamp; |
| 983 | common->ani.resetcal_timer = timestamp; |
| 984 | } |
| 985 | } else { |
| 986 | if ((timestamp - common->ani.resetcal_timer) >= |
| 987 | ATH_RESTART_CALINTERVAL) { |
| 988 | common->ani.caldone = ath9k_hw_reset_calvalid(ah); |
| 989 | if (common->ani.caldone) |
| 990 | common->ani.resetcal_timer = timestamp; |
| 991 | } |
| 992 | } |
| 993 | |
| 994 | /* Verify whether we must check ANI */ |
| 995 | if ((timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) { |
| 996 | aniflag = true; |
| 997 | common->ani.checkani_timer = timestamp; |
| 998 | } |
| 999 | |
| 1000 | /* Skip all processing if there's nothing to do. */ |
| 1001 | if (longcal || shortcal || aniflag) { |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1002 | |
| 1003 | ath9k_htc_ps_wakeup(priv); |
| 1004 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1005 | /* Call ANI routine if necessary */ |
| 1006 | if (aniflag) |
| 1007 | ath9k_hw_ani_monitor(ah, ah->curchan); |
| 1008 | |
| 1009 | /* Perform calibration if necessary */ |
Felix Fietkau | 35ecfe0 | 2010-09-29 17:15:26 +0200 | [diff] [blame] | 1010 | if (longcal || shortcal) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1011 | common->ani.caldone = |
| 1012 | ath9k_hw_calibrate(ah, ah->curchan, |
| 1013 | common->rx_chainmask, |
| 1014 | longcal); |
| 1015 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1016 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1017 | } |
| 1018 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1019 | set_timer: |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1020 | /* |
| 1021 | * Set timer interval based on previous results. |
| 1022 | * The interval must be the shortest necessary to satisfy ANI, |
| 1023 | * short calibration and long calibration. |
| 1024 | */ |
| 1025 | cal_interval = ATH_LONG_CALINTERVAL; |
| 1026 | if (priv->ah->config.enable_ani) |
| 1027 | cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL); |
| 1028 | if (!common->ani.caldone) |
| 1029 | cal_interval = min(cal_interval, (u32)short_cal_interval); |
| 1030 | |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 1031 | ieee80211_queue_delayed_work(common->hw, &priv->ani_work, |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1032 | msecs_to_jiffies(cal_interval)); |
| 1033 | } |
| 1034 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1035 | /**********************/ |
| 1036 | /* mac80211 Callbacks */ |
| 1037 | /**********************/ |
| 1038 | |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 1039 | static void ath9k_htc_tx(struct ieee80211_hw *hw, struct sk_buff *skb) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1040 | { |
| 1041 | struct ieee80211_hdr *hdr; |
| 1042 | struct ath9k_htc_priv *priv = hw->priv; |
Sujith | 7757dfe | 2010-03-29 16:07:17 +0530 | [diff] [blame] | 1043 | int padpos, padsize, ret; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1044 | |
| 1045 | hdr = (struct ieee80211_hdr *) skb->data; |
| 1046 | |
| 1047 | /* Add the padding after the header if this is not already done */ |
| 1048 | padpos = ath9k_cmn_padpos(hdr->frame_control); |
| 1049 | padsize = padpos & 3; |
| 1050 | if (padsize && skb->len > padpos) { |
| 1051 | if (skb_headroom(skb) < padsize) |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 1052 | goto fail_tx; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1053 | skb_push(skb, padsize); |
| 1054 | memmove(skb->data, skb->data + padsize, padpos); |
| 1055 | } |
| 1056 | |
Sujith | 7757dfe | 2010-03-29 16:07:17 +0530 | [diff] [blame] | 1057 | ret = ath9k_htc_tx_start(priv, skb); |
| 1058 | if (ret != 0) { |
| 1059 | if (ret == -ENOMEM) { |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 1060 | ath_dbg(ath9k_hw_common(priv->ah), ATH_DBG_XMIT, |
| 1061 | "Stopping TX queues\n"); |
Sujith | 7757dfe | 2010-03-29 16:07:17 +0530 | [diff] [blame] | 1062 | ieee80211_stop_queues(hw); |
| 1063 | spin_lock_bh(&priv->tx_lock); |
| 1064 | priv->tx_queues_stop = true; |
| 1065 | spin_unlock_bh(&priv->tx_lock); |
| 1066 | } else { |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 1067 | ath_dbg(ath9k_hw_common(priv->ah), ATH_DBG_XMIT, |
| 1068 | "Tx failed\n"); |
Sujith | 7757dfe | 2010-03-29 16:07:17 +0530 | [diff] [blame] | 1069 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1070 | goto fail_tx; |
| 1071 | } |
| 1072 | |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 1073 | return; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1074 | |
| 1075 | fail_tx: |
| 1076 | dev_kfree_skb_any(skb); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1077 | } |
| 1078 | |
Sujith | 881ac6a | 2010-06-01 15:14:11 +0530 | [diff] [blame] | 1079 | static int ath9k_htc_start(struct ieee80211_hw *hw) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1080 | { |
| 1081 | struct ath9k_htc_priv *priv = hw->priv; |
| 1082 | struct ath_hw *ah = priv->ah; |
| 1083 | struct ath_common *common = ath9k_hw_common(ah); |
| 1084 | struct ieee80211_channel *curchan = hw->conf.channel; |
| 1085 | struct ath9k_channel *init_channel; |
| 1086 | int ret = 0; |
| 1087 | enum htc_phymode mode; |
Sujith | 7f1f5a0 | 2010-04-16 11:54:03 +0530 | [diff] [blame] | 1088 | __be16 htc_mode; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1089 | u8 cmd_rsp; |
| 1090 | |
Sujith | 881ac6a | 2010-06-01 15:14:11 +0530 | [diff] [blame] | 1091 | mutex_lock(&priv->mutex); |
| 1092 | |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 1093 | ath_dbg(common, ATH_DBG_CONFIG, |
| 1094 | "Starting driver with initial channel: %d MHz\n", |
| 1095 | curchan->center_freq); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1096 | |
Sujith | 21d5130 | 2010-06-01 15:14:18 +0530 | [diff] [blame] | 1097 | /* Ensure that HW is awake before flushing RX */ |
| 1098 | ath9k_htc_setpower(priv, ATH9K_PM_AWAKE); |
| 1099 | WMI_CMD(WMI_FLUSH_RECV_CMDID); |
| 1100 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1101 | /* setup initial channel */ |
| 1102 | init_channel = ath9k_cmn_get_curchannel(hw, ah); |
| 1103 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1104 | ath9k_hw_htc_resetinit(ah); |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 1105 | ret = ath9k_hw_reset(ah, init_channel, ah->caldata, false); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1106 | if (ret) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 1107 | ath_err(common, |
| 1108 | "Unable to reset hardware; reset status %d (freq %u MHz)\n", |
| 1109 | ret, curchan->center_freq); |
Sujith | 881ac6a | 2010-06-01 15:14:11 +0530 | [diff] [blame] | 1110 | mutex_unlock(&priv->mutex); |
Vivek Natarajan | 8a8572a | 2010-04-27 13:05:37 +0530 | [diff] [blame] | 1111 | return ret; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1112 | } |
| 1113 | |
Rajkumar Manoharan | b2a5c3d | 2011-01-31 23:47:45 +0530 | [diff] [blame] | 1114 | ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit, |
| 1115 | &priv->curtxpow); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1116 | |
| 1117 | mode = ath9k_htc_get_curmode(priv, init_channel); |
| 1118 | htc_mode = cpu_to_be16(mode); |
| 1119 | WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1120 | WMI_CMD(WMI_ATH_INIT_CMDID); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1121 | WMI_CMD(WMI_START_RECV_CMDID); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1122 | |
| 1123 | ath9k_host_rx_init(priv); |
| 1124 | |
Sujith Manoharan | 1057b75 | 2011-02-21 07:48:09 +0530 | [diff] [blame] | 1125 | ret = ath9k_htc_update_cap_target(priv); |
| 1126 | if (ret) |
| 1127 | ath_dbg(common, ATH_DBG_CONFIG, |
| 1128 | "Failed to update capability in target\n"); |
| 1129 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1130 | priv->op_flags &= ~OP_INVALID; |
| 1131 | htc_start(priv->htc); |
| 1132 | |
Sujith | 7757dfe | 2010-03-29 16:07:17 +0530 | [diff] [blame] | 1133 | spin_lock_bh(&priv->tx_lock); |
| 1134 | priv->tx_queues_stop = false; |
| 1135 | spin_unlock_bh(&priv->tx_lock); |
| 1136 | |
| 1137 | ieee80211_wake_queues(hw); |
| 1138 | |
Vivek Natarajan | 21cb987 | 2010-08-18 19:57:49 +0530 | [diff] [blame] | 1139 | if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE) { |
| 1140 | ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT, |
| 1141 | AR_STOMP_LOW_WLAN_WGHT); |
| 1142 | ath9k_hw_btcoex_enable(ah); |
| 1143 | ath_htc_resume_btcoex_work(priv); |
| 1144 | } |
Vivek Natarajan | 8a8572a | 2010-04-27 13:05:37 +0530 | [diff] [blame] | 1145 | mutex_unlock(&priv->mutex); |
| 1146 | |
| 1147 | return ret; |
| 1148 | } |
| 1149 | |
Sujith | 881ac6a | 2010-06-01 15:14:11 +0530 | [diff] [blame] | 1150 | static void ath9k_htc_stop(struct ieee80211_hw *hw) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1151 | { |
| 1152 | struct ath9k_htc_priv *priv = hw->priv; |
| 1153 | struct ath_hw *ah = priv->ah; |
| 1154 | struct ath_common *common = ath9k_hw_common(ah); |
| 1155 | int ret = 0; |
| 1156 | u8 cmd_rsp; |
| 1157 | |
Sujith | 881ac6a | 2010-06-01 15:14:11 +0530 | [diff] [blame] | 1158 | mutex_lock(&priv->mutex); |
| 1159 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1160 | if (priv->op_flags & OP_INVALID) { |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 1161 | ath_dbg(common, ATH_DBG_ANY, "Device not present\n"); |
Sujith | 881ac6a | 2010-06-01 15:14:11 +0530 | [diff] [blame] | 1162 | mutex_unlock(&priv->mutex); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1163 | return; |
| 1164 | } |
| 1165 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1166 | ath9k_htc_ps_wakeup(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1167 | htc_stop(priv->htc); |
| 1168 | WMI_CMD(WMI_DISABLE_INTR_CMDID); |
| 1169 | WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID); |
| 1170 | WMI_CMD(WMI_STOP_RECV_CMDID); |
Stanislaw Gruszka | ea88835 | 2011-01-25 14:15:12 +0100 | [diff] [blame] | 1171 | |
| 1172 | tasklet_kill(&priv->swba_tasklet); |
| 1173 | tasklet_kill(&priv->rx_tasklet); |
| 1174 | tasklet_kill(&priv->tx_tasklet); |
| 1175 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1176 | skb_queue_purge(&priv->tx_queue); |
| 1177 | |
Stanislaw Gruszka | ea88835 | 2011-01-25 14:15:12 +0100 | [diff] [blame] | 1178 | mutex_unlock(&priv->mutex); |
| 1179 | |
| 1180 | /* Cancel all the running timers/work .. */ |
| 1181 | cancel_work_sync(&priv->fatal_work); |
| 1182 | cancel_work_sync(&priv->ps_work); |
| 1183 | cancel_delayed_work_sync(&priv->ath9k_led_blink_work); |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 1184 | ath9k_htc_stop_ani(priv); |
Stanislaw Gruszka | ea88835 | 2011-01-25 14:15:12 +0100 | [diff] [blame] | 1185 | ath9k_led_stop_brightness(priv); |
| 1186 | |
| 1187 | mutex_lock(&priv->mutex); |
| 1188 | |
Vivek Natarajan | 21cb987 | 2010-08-18 19:57:49 +0530 | [diff] [blame] | 1189 | if (ah->btcoex_hw.enabled) { |
| 1190 | ath9k_hw_btcoex_disable(ah); |
| 1191 | if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE) |
| 1192 | ath_htc_cancel_btcoex_work(priv); |
| 1193 | } |
| 1194 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 1195 | /* Remove a monitor interface if it's present. */ |
| 1196 | if (priv->ah->is_monitoring) |
| 1197 | ath9k_htc_remove_monitor_interface(priv); |
| 1198 | |
Sujith | e9201f0 | 2010-06-01 15:14:17 +0530 | [diff] [blame] | 1199 | ath9k_hw_phy_disable(ah); |
| 1200 | ath9k_hw_disable(ah); |
Sujith | e9201f0 | 2010-06-01 15:14:17 +0530 | [diff] [blame] | 1201 | ath9k_htc_ps_restore(priv); |
| 1202 | ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP); |
| 1203 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1204 | priv->op_flags |= OP_INVALID; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1205 | |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 1206 | ath_dbg(common, ATH_DBG_CONFIG, "Driver halt\n"); |
Vivek Natarajan | 8a8572a | 2010-04-27 13:05:37 +0530 | [diff] [blame] | 1207 | mutex_unlock(&priv->mutex); |
| 1208 | } |
| 1209 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1210 | static int ath9k_htc_add_interface(struct ieee80211_hw *hw, |
| 1211 | struct ieee80211_vif *vif) |
| 1212 | { |
| 1213 | struct ath9k_htc_priv *priv = hw->priv; |
| 1214 | struct ath9k_htc_vif *avp = (void *)vif->drv_priv; |
| 1215 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 1216 | struct ath9k_htc_target_vif hvif; |
| 1217 | int ret = 0; |
| 1218 | u8 cmd_rsp; |
| 1219 | |
| 1220 | mutex_lock(&priv->mutex); |
| 1221 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 1222 | if (priv->nvifs >= ATH9K_HTC_MAX_VIF) { |
Sujith Manoharan | ab77c70 | 2011-02-21 07:48:16 +0530 | [diff] [blame] | 1223 | mutex_unlock(&priv->mutex); |
Sujith Manoharan | 0df8359 | 2011-02-21 07:49:15 +0530 | [diff] [blame] | 1224 | return -ENOBUFS; |
| 1225 | } |
| 1226 | |
| 1227 | if (priv->num_ibss_vif || |
| 1228 | (priv->nvifs && vif->type == NL80211_IFTYPE_ADHOC)) { |
| 1229 | ath_err(common, "IBSS coexistence with other modes is not allowed\n"); |
| 1230 | mutex_unlock(&priv->mutex); |
| 1231 | return -ENOBUFS; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1232 | } |
| 1233 | |
Sujith Manoharan | da8d9d9 | 2011-02-21 07:49:23 +0530 | [diff] [blame] | 1234 | if (((vif->type == NL80211_IFTYPE_AP) || |
| 1235 | (vif->type == NL80211_IFTYPE_ADHOC)) && |
| 1236 | ((priv->num_ap_vif + priv->num_ibss_vif) >= ATH9K_HTC_MAX_BCN_VIF)) { |
| 1237 | ath_err(common, "Max. number of beaconing interfaces reached\n"); |
| 1238 | mutex_unlock(&priv->mutex); |
| 1239 | return -ENOBUFS; |
| 1240 | } |
| 1241 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1242 | ath9k_htc_ps_wakeup(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1243 | memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif)); |
| 1244 | memcpy(&hvif.myaddr, vif->addr, ETH_ALEN); |
| 1245 | |
| 1246 | switch (vif->type) { |
| 1247 | case NL80211_IFTYPE_STATION: |
| 1248 | hvif.opmode = cpu_to_be32(HTC_M_STA); |
| 1249 | break; |
| 1250 | case NL80211_IFTYPE_ADHOC: |
| 1251 | hvif.opmode = cpu_to_be32(HTC_M_IBSS); |
| 1252 | break; |
Sujith Manoharan | da8d9d9 | 2011-02-21 07:49:23 +0530 | [diff] [blame] | 1253 | case NL80211_IFTYPE_AP: |
| 1254 | hvif.opmode = cpu_to_be32(HTC_M_HOSTAP); |
| 1255 | break; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1256 | default: |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 1257 | ath_err(common, |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1258 | "Interface type %d not yet supported\n", vif->type); |
| 1259 | ret = -EOPNOTSUPP; |
| 1260 | goto out; |
| 1261 | } |
| 1262 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1263 | /* Index starts from zero on the target */ |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 1264 | avp->index = hvif.index = ffz(priv->vif_slot); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1265 | hvif.rtsthreshold = cpu_to_be16(2304); |
| 1266 | WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif); |
| 1267 | if (ret) |
| 1268 | goto out; |
| 1269 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1270 | /* |
| 1271 | * We need a node in target to tx mgmt frames |
| 1272 | * before association. |
| 1273 | */ |
| 1274 | ret = ath9k_htc_add_station(priv, vif, NULL); |
Sujith Manoharan | ab77c70 | 2011-02-21 07:48:16 +0530 | [diff] [blame] | 1275 | if (ret) { |
| 1276 | WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1277 | goto out; |
Sujith Manoharan | ab77c70 | 2011-02-21 07:48:16 +0530 | [diff] [blame] | 1278 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1279 | |
Sujith Manoharan | 585895c | 2011-02-21 07:48:46 +0530 | [diff] [blame] | 1280 | ath9k_htc_set_bssid_mask(priv, vif); |
| 1281 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 1282 | priv->vif_slot |= (1 << avp->index); |
Sujith Manoharan | ab77c70 | 2011-02-21 07:48:16 +0530 | [diff] [blame] | 1283 | priv->nvifs++; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1284 | priv->vif = vif; |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 1285 | |
Sujith Manoharan | 0df8359 | 2011-02-21 07:49:15 +0530 | [diff] [blame] | 1286 | INC_VIF(priv, vif->type); |
Sujith Manoharan | ffbe7c8 | 2011-02-21 07:49:31 +0530 | [diff] [blame] | 1287 | ath9k_htc_set_opmode(priv); |
Sujith Manoharan | 0df8359 | 2011-02-21 07:49:15 +0530 | [diff] [blame] | 1288 | |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 1289 | if ((priv->ah->opmode == NL80211_IFTYPE_AP) && |
| 1290 | !(priv->op_flags & OP_ANI_RUNNING)) |
| 1291 | ath9k_htc_start_ani(priv); |
| 1292 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 1293 | ath_dbg(common, ATH_DBG_CONFIG, |
| 1294 | "Attach a VIF of type: %d at idx: %d\n", vif->type, avp->index); |
| 1295 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1296 | out: |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1297 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1298 | mutex_unlock(&priv->mutex); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1299 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1300 | return ret; |
| 1301 | } |
| 1302 | |
| 1303 | static void ath9k_htc_remove_interface(struct ieee80211_hw *hw, |
| 1304 | struct ieee80211_vif *vif) |
| 1305 | { |
| 1306 | struct ath9k_htc_priv *priv = hw->priv; |
| 1307 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 1308 | struct ath9k_htc_vif *avp = (void *)vif->drv_priv; |
| 1309 | struct ath9k_htc_target_vif hvif; |
| 1310 | int ret = 0; |
| 1311 | u8 cmd_rsp; |
| 1312 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1313 | mutex_lock(&priv->mutex); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1314 | ath9k_htc_ps_wakeup(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1315 | |
| 1316 | memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif)); |
| 1317 | memcpy(&hvif.myaddr, vif->addr, ETH_ALEN); |
| 1318 | hvif.index = avp->index; |
| 1319 | WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif); |
| 1320 | priv->nvifs--; |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 1321 | priv->vif_slot &= ~(1 << avp->index); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1322 | |
| 1323 | ath9k_htc_remove_station(priv, vif, NULL); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1324 | priv->vif = NULL; |
| 1325 | |
Sujith Manoharan | 0df8359 | 2011-02-21 07:49:15 +0530 | [diff] [blame] | 1326 | DEC_VIF(priv, vif->type); |
Sujith Manoharan | ffbe7c8 | 2011-02-21 07:49:31 +0530 | [diff] [blame] | 1327 | ath9k_htc_set_opmode(priv); |
Sujith Manoharan | 0df8359 | 2011-02-21 07:49:15 +0530 | [diff] [blame] | 1328 | |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 1329 | /* |
| 1330 | * Stop ANI only if there are no associated station interfaces. |
| 1331 | */ |
| 1332 | if ((vif->type == NL80211_IFTYPE_AP) && (priv->num_ap_vif == 0)) { |
| 1333 | priv->rearm_ani = false; |
| 1334 | ieee80211_iterate_active_interfaces_atomic(priv->hw, |
| 1335 | ath9k_htc_vif_iter, priv); |
| 1336 | if (!priv->rearm_ani) |
| 1337 | ath9k_htc_stop_ani(priv); |
| 1338 | } |
| 1339 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 1340 | ath_dbg(common, ATH_DBG_CONFIG, "Detach Interface at idx: %d\n", avp->index); |
| 1341 | |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1342 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1343 | mutex_unlock(&priv->mutex); |
| 1344 | } |
| 1345 | |
| 1346 | static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed) |
| 1347 | { |
| 1348 | struct ath9k_htc_priv *priv = hw->priv; |
| 1349 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 1350 | struct ieee80211_conf *conf = &hw->conf; |
| 1351 | |
| 1352 | mutex_lock(&priv->mutex); |
| 1353 | |
Vivek Natarajan | 8a8572a | 2010-04-27 13:05:37 +0530 | [diff] [blame] | 1354 | if (changed & IEEE80211_CONF_CHANGE_IDLE) { |
| 1355 | bool enable_radio = false; |
| 1356 | bool idle = !!(conf->flags & IEEE80211_CONF_IDLE); |
| 1357 | |
Sujith | 2336776 | 2010-06-01 15:14:16 +0530 | [diff] [blame] | 1358 | mutex_lock(&priv->htc_pm_lock); |
Vivek Natarajan | 8a8572a | 2010-04-27 13:05:37 +0530 | [diff] [blame] | 1359 | if (!idle && priv->ps_idle) |
| 1360 | enable_radio = true; |
Vivek Natarajan | 8a8572a | 2010-04-27 13:05:37 +0530 | [diff] [blame] | 1361 | priv->ps_idle = idle; |
Sujith | 2336776 | 2010-06-01 15:14:16 +0530 | [diff] [blame] | 1362 | mutex_unlock(&priv->htc_pm_lock); |
Vivek Natarajan | 8a8572a | 2010-04-27 13:05:37 +0530 | [diff] [blame] | 1363 | |
| 1364 | if (enable_radio) { |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 1365 | ath_dbg(common, ATH_DBG_CONFIG, |
| 1366 | "not-idle: enabling radio\n"); |
Sujith | 2336776 | 2010-06-01 15:14:16 +0530 | [diff] [blame] | 1367 | ath9k_htc_setpower(priv, ATH9K_PM_AWAKE); |
| 1368 | ath9k_htc_radio_enable(hw); |
Vivek Natarajan | 8a8572a | 2010-04-27 13:05:37 +0530 | [diff] [blame] | 1369 | } |
| 1370 | } |
| 1371 | |
Sujith Manoharan | 55de80d | 2011-01-05 01:06:21 +0530 | [diff] [blame] | 1372 | /* |
| 1373 | * Monitor interface should be added before |
| 1374 | * IEEE80211_CONF_CHANGE_CHANNEL is handled. |
| 1375 | */ |
| 1376 | if (changed & IEEE80211_CONF_CHANGE_MONITOR) { |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 1377 | if ((conf->flags & IEEE80211_CONF_MONITOR) && |
| 1378 | !priv->ah->is_monitoring) |
| 1379 | ath9k_htc_add_monitor_interface(priv); |
| 1380 | else if (priv->ah->is_monitoring) |
| 1381 | ath9k_htc_remove_monitor_interface(priv); |
Sujith Manoharan | 55de80d | 2011-01-05 01:06:21 +0530 | [diff] [blame] | 1382 | } |
| 1383 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1384 | if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { |
| 1385 | struct ieee80211_channel *curchan = hw->conf.channel; |
| 1386 | int pos = curchan->hw_value; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1387 | |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 1388 | ath_dbg(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n", |
| 1389 | curchan->center_freq); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1390 | |
Felix Fietkau | babcbc2 | 2010-10-20 02:09:46 +0200 | [diff] [blame] | 1391 | ath9k_cmn_update_ichannel(&priv->ah->channels[pos], |
| 1392 | hw->conf.channel, |
| 1393 | hw->conf.channel_type); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1394 | |
| 1395 | if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 1396 | ath_err(common, "Unable to set channel\n"); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1397 | mutex_unlock(&priv->mutex); |
| 1398 | return -EINVAL; |
| 1399 | } |
| 1400 | |
| 1401 | } |
Sujith Manoharan | 692d6b1 | 2010-12-07 16:31:54 +0530 | [diff] [blame] | 1402 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1403 | if (changed & IEEE80211_CONF_CHANGE_PS) { |
| 1404 | if (conf->flags & IEEE80211_CONF_PS) { |
| 1405 | ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP); |
| 1406 | priv->ps_enabled = true; |
| 1407 | } else { |
| 1408 | priv->ps_enabled = false; |
| 1409 | cancel_work_sync(&priv->ps_work); |
| 1410 | ath9k_htc_setpower(priv, ATH9K_PM_AWAKE); |
| 1411 | } |
| 1412 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1413 | |
Sujith Manoharan | 692d6b1 | 2010-12-07 16:31:54 +0530 | [diff] [blame] | 1414 | if (changed & IEEE80211_CONF_CHANGE_POWER) { |
| 1415 | priv->txpowlimit = 2 * conf->power_level; |
Rajkumar Manoharan | b2a5c3d | 2011-01-31 23:47:45 +0530 | [diff] [blame] | 1416 | ath9k_cmn_update_txpow(priv->ah, priv->curtxpow, |
| 1417 | priv->txpowlimit, &priv->curtxpow); |
Sujith Manoharan | 692d6b1 | 2010-12-07 16:31:54 +0530 | [diff] [blame] | 1418 | } |
| 1419 | |
Sujith | 2336776 | 2010-06-01 15:14:16 +0530 | [diff] [blame] | 1420 | if (changed & IEEE80211_CONF_CHANGE_IDLE) { |
| 1421 | mutex_lock(&priv->htc_pm_lock); |
| 1422 | if (!priv->ps_idle) { |
| 1423 | mutex_unlock(&priv->htc_pm_lock); |
| 1424 | goto out; |
| 1425 | } |
| 1426 | mutex_unlock(&priv->htc_pm_lock); |
| 1427 | |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 1428 | ath_dbg(common, ATH_DBG_CONFIG, |
| 1429 | "idle: disabling radio\n"); |
Sujith | 881ac6a | 2010-06-01 15:14:11 +0530 | [diff] [blame] | 1430 | ath9k_htc_radio_disable(hw); |
Vivek Natarajan | 8a8572a | 2010-04-27 13:05:37 +0530 | [diff] [blame] | 1431 | } |
| 1432 | |
Sujith | 2336776 | 2010-06-01 15:14:16 +0530 | [diff] [blame] | 1433 | out: |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1434 | mutex_unlock(&priv->mutex); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1435 | return 0; |
| 1436 | } |
| 1437 | |
| 1438 | #define SUPPORTED_FILTERS \ |
| 1439 | (FIF_PROMISC_IN_BSS | \ |
| 1440 | FIF_ALLMULTI | \ |
| 1441 | FIF_CONTROL | \ |
| 1442 | FIF_PSPOLL | \ |
| 1443 | FIF_OTHER_BSS | \ |
| 1444 | FIF_BCN_PRBRESP_PROMISC | \ |
Rajkumar Manoharan | 94a40c0 | 2010-10-14 10:50:26 +0530 | [diff] [blame] | 1445 | FIF_PROBE_REQ | \ |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1446 | FIF_FCSFAIL) |
| 1447 | |
| 1448 | static void ath9k_htc_configure_filter(struct ieee80211_hw *hw, |
| 1449 | unsigned int changed_flags, |
| 1450 | unsigned int *total_flags, |
| 1451 | u64 multicast) |
| 1452 | { |
| 1453 | struct ath9k_htc_priv *priv = hw->priv; |
| 1454 | u32 rfilt; |
| 1455 | |
| 1456 | mutex_lock(&priv->mutex); |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1457 | ath9k_htc_ps_wakeup(priv); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1458 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1459 | changed_flags &= SUPPORTED_FILTERS; |
| 1460 | *total_flags &= SUPPORTED_FILTERS; |
| 1461 | |
| 1462 | priv->rxfilter = *total_flags; |
Sujith | 0995d11 | 2010-03-29 16:07:09 +0530 | [diff] [blame] | 1463 | rfilt = ath9k_htc_calcrxfilter(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1464 | ath9k_hw_setrxfilter(priv->ah, rfilt); |
| 1465 | |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 1466 | ath_dbg(ath9k_hw_common(priv->ah), ATH_DBG_CONFIG, |
| 1467 | "Set HW RX filter: 0x%x\n", rfilt); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1468 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1469 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1470 | mutex_unlock(&priv->mutex); |
| 1471 | } |
| 1472 | |
Sujith | abd984e | 2010-05-18 15:26:04 +0530 | [diff] [blame] | 1473 | static int ath9k_htc_sta_add(struct ieee80211_hw *hw, |
| 1474 | struct ieee80211_vif *vif, |
| 1475 | struct ieee80211_sta *sta) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1476 | { |
| 1477 | struct ath9k_htc_priv *priv = hw->priv; |
| 1478 | int ret; |
| 1479 | |
Sujith.Manoharan@atheros.com | 05a30f9 | 2010-05-11 16:24:38 +0530 | [diff] [blame] | 1480 | mutex_lock(&priv->mutex); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1481 | ath9k_htc_ps_wakeup(priv); |
Sujith | abd984e | 2010-05-18 15:26:04 +0530 | [diff] [blame] | 1482 | ret = ath9k_htc_add_station(priv, vif, sta); |
| 1483 | if (!ret) |
| 1484 | ath9k_htc_init_rate(priv, sta); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1485 | ath9k_htc_ps_restore(priv); |
Sujith.Manoharan@atheros.com | 05a30f9 | 2010-05-11 16:24:38 +0530 | [diff] [blame] | 1486 | mutex_unlock(&priv->mutex); |
Sujith | abd984e | 2010-05-18 15:26:04 +0530 | [diff] [blame] | 1487 | |
| 1488 | return ret; |
| 1489 | } |
| 1490 | |
| 1491 | static int ath9k_htc_sta_remove(struct ieee80211_hw *hw, |
| 1492 | struct ieee80211_vif *vif, |
| 1493 | struct ieee80211_sta *sta) |
| 1494 | { |
| 1495 | struct ath9k_htc_priv *priv = hw->priv; |
| 1496 | int ret; |
| 1497 | |
| 1498 | mutex_lock(&priv->mutex); |
| 1499 | ath9k_htc_ps_wakeup(priv); |
| 1500 | ret = ath9k_htc_remove_station(priv, vif, sta); |
| 1501 | ath9k_htc_ps_restore(priv); |
| 1502 | mutex_unlock(&priv->mutex); |
| 1503 | |
| 1504 | return ret; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1505 | } |
| 1506 | |
| 1507 | static int ath9k_htc_conf_tx(struct ieee80211_hw *hw, u16 queue, |
| 1508 | const struct ieee80211_tx_queue_params *params) |
| 1509 | { |
| 1510 | struct ath9k_htc_priv *priv = hw->priv; |
| 1511 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 1512 | struct ath9k_tx_queue_info qi; |
| 1513 | int ret = 0, qnum; |
| 1514 | |
| 1515 | if (queue >= WME_NUM_AC) |
| 1516 | return 0; |
| 1517 | |
| 1518 | mutex_lock(&priv->mutex); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1519 | ath9k_htc_ps_wakeup(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1520 | |
| 1521 | memset(&qi, 0, sizeof(struct ath9k_tx_queue_info)); |
| 1522 | |
| 1523 | qi.tqi_aifs = params->aifs; |
| 1524 | qi.tqi_cwmin = params->cw_min; |
| 1525 | qi.tqi_cwmax = params->cw_max; |
| 1526 | qi.tqi_burstTime = params->txop; |
| 1527 | |
| 1528 | qnum = get_hw_qnum(queue, priv->hwq_map); |
| 1529 | |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 1530 | ath_dbg(common, ATH_DBG_CONFIG, |
| 1531 | "Configure tx [queue/hwq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n", |
| 1532 | queue, qnum, params->aifs, params->cw_min, |
| 1533 | params->cw_max, params->txop); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1534 | |
Sujith | e1572c5 | 2010-03-24 13:42:13 +0530 | [diff] [blame] | 1535 | ret = ath_htc_txq_update(priv, qnum, &qi); |
Sujith | 764580f | 2010-06-01 15:14:19 +0530 | [diff] [blame] | 1536 | if (ret) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 1537 | ath_err(common, "TXQ Update failed\n"); |
Sujith | 764580f | 2010-06-01 15:14:19 +0530 | [diff] [blame] | 1538 | goto out; |
| 1539 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1540 | |
Sujith | 764580f | 2010-06-01 15:14:19 +0530 | [diff] [blame] | 1541 | if ((priv->ah->opmode == NL80211_IFTYPE_ADHOC) && |
Felix Fietkau | e8c35a7 | 2010-06-12 00:33:50 -0400 | [diff] [blame] | 1542 | (qnum == priv->hwq_map[WME_AC_BE])) |
Sujith | 764580f | 2010-06-01 15:14:19 +0530 | [diff] [blame] | 1543 | ath9k_htc_beaconq_config(priv); |
| 1544 | out: |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1545 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1546 | mutex_unlock(&priv->mutex); |
| 1547 | |
| 1548 | return ret; |
| 1549 | } |
| 1550 | |
| 1551 | static int ath9k_htc_set_key(struct ieee80211_hw *hw, |
| 1552 | enum set_key_cmd cmd, |
| 1553 | struct ieee80211_vif *vif, |
| 1554 | struct ieee80211_sta *sta, |
| 1555 | struct ieee80211_key_conf *key) |
| 1556 | { |
| 1557 | struct ath9k_htc_priv *priv = hw->priv; |
| 1558 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 1559 | int ret = 0; |
| 1560 | |
Sujith | e1572c5 | 2010-03-24 13:42:13 +0530 | [diff] [blame] | 1561 | if (htc_modparam_nohwcrypt) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1562 | return -ENOSPC; |
| 1563 | |
| 1564 | mutex_lock(&priv->mutex); |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 1565 | ath_dbg(common, ATH_DBG_CONFIG, "Set HW Key\n"); |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1566 | ath9k_htc_ps_wakeup(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1567 | |
| 1568 | switch (cmd) { |
| 1569 | case SET_KEY: |
Bruno Randolf | 040e539 | 2010-09-08 16:05:04 +0900 | [diff] [blame] | 1570 | ret = ath_key_config(common, vif, sta, key); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1571 | if (ret >= 0) { |
| 1572 | key->hw_key_idx = ret; |
| 1573 | /* push IV and Michael MIC generation to stack */ |
| 1574 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 1575 | if (key->cipher == WLAN_CIPHER_SUITE_TKIP) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1576 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 1577 | if (priv->ah->sw_mgmt_crypto && |
| 1578 | key->cipher == WLAN_CIPHER_SUITE_CCMP) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1579 | key->flags |= IEEE80211_KEY_FLAG_SW_MGMT; |
| 1580 | ret = 0; |
| 1581 | } |
| 1582 | break; |
| 1583 | case DISABLE_KEY: |
Bruno Randolf | 040e539 | 2010-09-08 16:05:04 +0900 | [diff] [blame] | 1584 | ath_key_delete(common, key); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1585 | break; |
| 1586 | default: |
| 1587 | ret = -EINVAL; |
| 1588 | } |
| 1589 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1590 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1591 | mutex_unlock(&priv->mutex); |
| 1592 | |
| 1593 | return ret; |
| 1594 | } |
| 1595 | |
| 1596 | static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw, |
| 1597 | struct ieee80211_vif *vif, |
| 1598 | struct ieee80211_bss_conf *bss_conf, |
| 1599 | u32 changed) |
| 1600 | { |
| 1601 | struct ath9k_htc_priv *priv = hw->priv; |
| 1602 | struct ath_hw *ah = priv->ah; |
| 1603 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith Manoharan | e7a2a4f | 2011-02-27 09:20:40 +0530 | [diff] [blame^] | 1604 | bool set_assoc; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1605 | |
| 1606 | mutex_lock(&priv->mutex); |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1607 | ath9k_htc_ps_wakeup(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1608 | |
Sujith Manoharan | e7a2a4f | 2011-02-27 09:20:40 +0530 | [diff] [blame^] | 1609 | /* |
| 1610 | * Set the HW AID/BSSID only for the first station interface |
| 1611 | * or in IBSS mode. |
| 1612 | */ |
| 1613 | set_assoc = !!((priv->ah->opmode == NL80211_IFTYPE_ADHOC) || |
| 1614 | ((priv->ah->opmode == NL80211_IFTYPE_STATION) && |
| 1615 | (priv->num_sta_vif == 1))); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1616 | |
Sujith Manoharan | e7a2a4f | 2011-02-27 09:20:40 +0530 | [diff] [blame^] | 1617 | |
| 1618 | if (changed & BSS_CHANGED_ASSOC) { |
| 1619 | if (set_assoc) { |
| 1620 | ath_dbg(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n", |
| 1621 | bss_conf->assoc); |
| 1622 | |
| 1623 | common->curaid = bss_conf->assoc ? |
| 1624 | bss_conf->aid : 0; |
| 1625 | |
| 1626 | if (bss_conf->assoc) |
| 1627 | ath9k_htc_start_ani(priv); |
| 1628 | else |
| 1629 | ath9k_htc_stop_ani(priv); |
| 1630 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1631 | } |
| 1632 | |
| 1633 | if (changed & BSS_CHANGED_BSSID) { |
Sujith Manoharan | e7a2a4f | 2011-02-27 09:20:40 +0530 | [diff] [blame^] | 1634 | if (set_assoc) { |
| 1635 | memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN); |
| 1636 | ath9k_hw_write_associd(ah); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1637 | |
Sujith Manoharan | e7a2a4f | 2011-02-27 09:20:40 +0530 | [diff] [blame^] | 1638 | ath_dbg(common, ATH_DBG_CONFIG, |
| 1639 | "BSSID: %pM aid: 0x%x\n", |
| 1640 | common->curbssid, common->curaid); |
| 1641 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1642 | } |
| 1643 | |
Sujith Manoharan | a5fae37 | 2011-02-21 07:49:53 +0530 | [diff] [blame] | 1644 | if ((changed & BSS_CHANGED_BEACON_ENABLED) && bss_conf->enable_beacon) { |
| 1645 | ath_dbg(common, ATH_DBG_CONFIG, |
| 1646 | "Beacon enabled for BSS: %pM\n", bss_conf->bssid); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1647 | priv->op_flags |= OP_ENABLE_BEACON; |
Vivek Natarajan | 1c3652a | 2010-04-05 14:48:06 +0530 | [diff] [blame] | 1648 | ath9k_htc_beacon_config(priv, vif); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1649 | } |
| 1650 | |
Sujith Manoharan | a5fae37 | 2011-02-21 07:49:53 +0530 | [diff] [blame] | 1651 | if ((changed & BSS_CHANGED_BEACON_ENABLED) && !bss_conf->enable_beacon) { |
| 1652 | /* |
| 1653 | * Disable SWBA interrupt only if there are no |
| 1654 | * AP/IBSS interfaces. |
| 1655 | */ |
| 1656 | if ((priv->num_ap_vif <= 1) || priv->num_ibss_vif) { |
| 1657 | ath_dbg(common, ATH_DBG_CONFIG, |
| 1658 | "Beacon disabled for BSS: %pM\n", |
| 1659 | bss_conf->bssid); |
| 1660 | priv->op_flags &= ~OP_ENABLE_BEACON; |
| 1661 | ath9k_htc_beacon_config(priv, vif); |
| 1662 | } |
| 1663 | } |
| 1664 | |
| 1665 | if (changed & BSS_CHANGED_BEACON_INT) { |
| 1666 | /* |
| 1667 | * Reset the HW TSF for the first AP interface. |
| 1668 | */ |
| 1669 | if ((priv->ah->opmode == NL80211_IFTYPE_AP) && |
| 1670 | (priv->nvifs == 1) && |
| 1671 | (priv->num_ap_vif == 1) && |
| 1672 | (vif->type == NL80211_IFTYPE_AP)) { |
| 1673 | priv->op_flags |= OP_TSF_RESET; |
| 1674 | } |
| 1675 | ath_dbg(common, ATH_DBG_CONFIG, |
| 1676 | "Beacon interval changed for BSS: %pM\n", |
| 1677 | bss_conf->bssid); |
Vivek Natarajan | 1c3652a | 2010-04-05 14:48:06 +0530 | [diff] [blame] | 1678 | ath9k_htc_beacon_config(priv, vif); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1679 | } |
| 1680 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1681 | if (changed & BSS_CHANGED_ERP_SLOT) { |
| 1682 | if (bss_conf->use_short_slot) |
| 1683 | ah->slottime = 9; |
| 1684 | else |
| 1685 | ah->slottime = 20; |
| 1686 | |
| 1687 | ath9k_hw_init_global_settings(ah); |
| 1688 | } |
| 1689 | |
Sujith | 2c76ef8 | 2010-05-17 12:01:18 +0530 | [diff] [blame] | 1690 | if (changed & BSS_CHANGED_HT) |
| 1691 | ath9k_htc_update_rate(priv, vif, bss_conf); |
| 1692 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1693 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1694 | mutex_unlock(&priv->mutex); |
| 1695 | } |
| 1696 | |
| 1697 | static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw) |
| 1698 | { |
| 1699 | struct ath9k_htc_priv *priv = hw->priv; |
| 1700 | u64 tsf; |
| 1701 | |
| 1702 | mutex_lock(&priv->mutex); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1703 | ath9k_htc_ps_wakeup(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1704 | tsf = ath9k_hw_gettsf64(priv->ah); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1705 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1706 | mutex_unlock(&priv->mutex); |
| 1707 | |
| 1708 | return tsf; |
| 1709 | } |
| 1710 | |
| 1711 | static void ath9k_htc_set_tsf(struct ieee80211_hw *hw, u64 tsf) |
| 1712 | { |
| 1713 | struct ath9k_htc_priv *priv = hw->priv; |
| 1714 | |
| 1715 | mutex_lock(&priv->mutex); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1716 | ath9k_htc_ps_wakeup(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1717 | ath9k_hw_settsf64(priv->ah, tsf); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1718 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1719 | mutex_unlock(&priv->mutex); |
| 1720 | } |
| 1721 | |
| 1722 | static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw) |
| 1723 | { |
| 1724 | struct ath9k_htc_priv *priv = hw->priv; |
| 1725 | |
| 1726 | mutex_lock(&priv->mutex); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1727 | ath9k_htc_ps_wakeup(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1728 | ath9k_hw_reset_tsf(priv->ah); |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1729 | ath9k_htc_ps_restore(priv); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1730 | mutex_unlock(&priv->mutex); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1731 | } |
| 1732 | |
| 1733 | static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw, |
| 1734 | struct ieee80211_vif *vif, |
| 1735 | enum ieee80211_ampdu_mlme_action action, |
| 1736 | struct ieee80211_sta *sta, |
Johannes Berg | 0b01f03 | 2011-01-18 13:51:05 +0100 | [diff] [blame] | 1737 | u16 tid, u16 *ssn, u8 buf_size) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1738 | { |
| 1739 | struct ath9k_htc_priv *priv = hw->priv; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1740 | struct ath9k_htc_sta *ista; |
Sujith | d7ca213 | 2010-06-15 10:24:37 +0530 | [diff] [blame] | 1741 | int ret = 0; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1742 | |
Sujith Manoharan | 87df895 | 2011-02-21 07:49:08 +0530 | [diff] [blame] | 1743 | mutex_lock(&priv->mutex); |
| 1744 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1745 | switch (action) { |
| 1746 | case IEEE80211_AMPDU_RX_START: |
| 1747 | break; |
| 1748 | case IEEE80211_AMPDU_RX_STOP: |
| 1749 | break; |
| 1750 | case IEEE80211_AMPDU_TX_START: |
Sujith | d7ca213 | 2010-06-15 10:24:37 +0530 | [diff] [blame] | 1751 | ret = ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid); |
| 1752 | if (!ret) |
| 1753 | ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 1754 | break; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1755 | case IEEE80211_AMPDU_TX_STOP: |
Sujith | d7ca213 | 2010-06-15 10:24:37 +0530 | [diff] [blame] | 1756 | ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid); |
| 1757 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1758 | break; |
| 1759 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
| 1760 | ista = (struct ath9k_htc_sta *) sta->drv_priv; |
Sujith | d7ca213 | 2010-06-15 10:24:37 +0530 | [diff] [blame] | 1761 | spin_lock_bh(&priv->tx_lock); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1762 | ista->tid_state[tid] = AGGR_OPERATIONAL; |
Sujith | d7ca213 | 2010-06-15 10:24:37 +0530 | [diff] [blame] | 1763 | spin_unlock_bh(&priv->tx_lock); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1764 | break; |
| 1765 | default: |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 1766 | ath_err(ath9k_hw_common(priv->ah), "Unknown AMPDU action\n"); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1767 | } |
| 1768 | |
Sujith Manoharan | 87df895 | 2011-02-21 07:49:08 +0530 | [diff] [blame] | 1769 | mutex_unlock(&priv->mutex); |
| 1770 | |
Sujith | d7ca213 | 2010-06-15 10:24:37 +0530 | [diff] [blame] | 1771 | return ret; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1772 | } |
| 1773 | |
| 1774 | static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw) |
| 1775 | { |
| 1776 | struct ath9k_htc_priv *priv = hw->priv; |
| 1777 | |
| 1778 | mutex_lock(&priv->mutex); |
| 1779 | spin_lock_bh(&priv->beacon_lock); |
| 1780 | priv->op_flags |= OP_SCANNING; |
| 1781 | spin_unlock_bh(&priv->beacon_lock); |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1782 | cancel_work_sync(&priv->ps_work); |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 1783 | ath9k_htc_stop_ani(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1784 | mutex_unlock(&priv->mutex); |
| 1785 | } |
| 1786 | |
| 1787 | static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw) |
| 1788 | { |
| 1789 | struct ath9k_htc_priv *priv = hw->priv; |
| 1790 | |
| 1791 | mutex_lock(&priv->mutex); |
| 1792 | spin_lock_bh(&priv->beacon_lock); |
| 1793 | priv->op_flags &= ~OP_SCANNING; |
| 1794 | spin_unlock_bh(&priv->beacon_lock); |
Sujith Manoharan | 7c27734 | 2011-02-21 07:48:39 +0530 | [diff] [blame] | 1795 | ath9k_htc_ps_wakeup(priv); |
| 1796 | ath9k_htc_vif_reconfig(priv); |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1797 | ath9k_htc_ps_restore(priv); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1798 | mutex_unlock(&priv->mutex); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1799 | } |
| 1800 | |
| 1801 | static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value) |
| 1802 | { |
| 1803 | return 0; |
| 1804 | } |
| 1805 | |
| 1806 | static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw, |
| 1807 | u8 coverage_class) |
| 1808 | { |
| 1809 | struct ath9k_htc_priv *priv = hw->priv; |
| 1810 | |
| 1811 | mutex_lock(&priv->mutex); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1812 | ath9k_htc_ps_wakeup(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1813 | priv->ah->coverage_class = coverage_class; |
| 1814 | ath9k_hw_init_global_settings(priv->ah); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1815 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1816 | mutex_unlock(&priv->mutex); |
| 1817 | } |
| 1818 | |
| 1819 | struct ieee80211_ops ath9k_htc_ops = { |
| 1820 | .tx = ath9k_htc_tx, |
| 1821 | .start = ath9k_htc_start, |
| 1822 | .stop = ath9k_htc_stop, |
| 1823 | .add_interface = ath9k_htc_add_interface, |
| 1824 | .remove_interface = ath9k_htc_remove_interface, |
| 1825 | .config = ath9k_htc_config, |
| 1826 | .configure_filter = ath9k_htc_configure_filter, |
Sujith | abd984e | 2010-05-18 15:26:04 +0530 | [diff] [blame] | 1827 | .sta_add = ath9k_htc_sta_add, |
| 1828 | .sta_remove = ath9k_htc_sta_remove, |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1829 | .conf_tx = ath9k_htc_conf_tx, |
| 1830 | .bss_info_changed = ath9k_htc_bss_info_changed, |
| 1831 | .set_key = ath9k_htc_set_key, |
| 1832 | .get_tsf = ath9k_htc_get_tsf, |
| 1833 | .set_tsf = ath9k_htc_set_tsf, |
| 1834 | .reset_tsf = ath9k_htc_reset_tsf, |
| 1835 | .ampdu_action = ath9k_htc_ampdu_action, |
| 1836 | .sw_scan_start = ath9k_htc_sw_scan_start, |
| 1837 | .sw_scan_complete = ath9k_htc_sw_scan_complete, |
| 1838 | .set_rts_threshold = ath9k_htc_set_rts_threshold, |
| 1839 | .rfkill_poll = ath9k_htc_rfkill_poll_state, |
| 1840 | .set_coverage_class = ath9k_htc_set_coverage_class, |
| 1841 | }; |