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