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