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