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