Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1 | /* |
Sujith Manoharan | 5b68138 | 2011-05-17 13:36:18 +0530 | [diff] [blame] | 2 | * Copyright (c) 2010-2011 Atheros Communications Inc. |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 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 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 19 | /*************/ |
| 20 | /* Utilities */ |
| 21 | /*************/ |
| 22 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 23 | /* HACK Alert: Use 11NG for 2.4, use 11NA for 5 */ |
| 24 | static enum htc_phymode ath9k_htc_get_curmode(struct ath9k_htc_priv *priv, |
| 25 | struct ath9k_channel *ichan) |
| 26 | { |
Felix Fietkau | 8896934 | 2013-10-11 23:30:53 +0200 | [diff] [blame] | 27 | if (IS_CHAN_5GHZ(ichan)) |
| 28 | return HTC_MODE_11NA; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 29 | |
Felix Fietkau | 8896934 | 2013-10-11 23:30:53 +0200 | [diff] [blame] | 30 | return HTC_MODE_11NG; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 31 | } |
| 32 | |
Sujith Manoharan | f933ebe | 2010-12-01 12:30:27 +0530 | [diff] [blame] | 33 | bool ath9k_htc_setpower(struct ath9k_htc_priv *priv, |
| 34 | enum ath9k_power_mode mode) |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 35 | { |
| 36 | bool ret; |
| 37 | |
| 38 | mutex_lock(&priv->htc_pm_lock); |
| 39 | ret = ath9k_hw_setpower(priv->ah, mode); |
| 40 | mutex_unlock(&priv->htc_pm_lock); |
| 41 | |
| 42 | return ret; |
| 43 | } |
| 44 | |
| 45 | void ath9k_htc_ps_wakeup(struct ath9k_htc_priv *priv) |
| 46 | { |
| 47 | mutex_lock(&priv->htc_pm_lock); |
| 48 | if (++priv->ps_usecount != 1) |
| 49 | goto unlock; |
| 50 | ath9k_hw_setpower(priv->ah, ATH9K_PM_AWAKE); |
| 51 | |
| 52 | unlock: |
| 53 | mutex_unlock(&priv->htc_pm_lock); |
| 54 | } |
| 55 | |
| 56 | void ath9k_htc_ps_restore(struct ath9k_htc_priv *priv) |
| 57 | { |
Sujith Manoharan | 6bcfe67 | 2012-06-25 13:54:49 +0530 | [diff] [blame] | 58 | bool reset; |
| 59 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 60 | mutex_lock(&priv->htc_pm_lock); |
| 61 | if (--priv->ps_usecount != 0) |
| 62 | goto unlock; |
| 63 | |
Sujith Manoharan | 6bcfe67 | 2012-06-25 13:54:49 +0530 | [diff] [blame] | 64 | if (priv->ps_idle) { |
| 65 | ath9k_hw_setrxabort(priv->ah, true); |
| 66 | ath9k_hw_stopdmarecv(priv->ah, &reset); |
Vivek Natarajan | 8a8572a | 2010-04-27 13:05:37 +0530 | [diff] [blame] | 67 | ath9k_hw_setpower(priv->ah, ATH9K_PM_FULL_SLEEP); |
Sujith Manoharan | 6bcfe67 | 2012-06-25 13:54:49 +0530 | [diff] [blame] | 68 | } else if (priv->ps_enabled) { |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 69 | ath9k_hw_setpower(priv->ah, ATH9K_PM_NETWORK_SLEEP); |
Sujith Manoharan | 6bcfe67 | 2012-06-25 13:54:49 +0530 | [diff] [blame] | 70 | } |
Vivek Natarajan | 8a8572a | 2010-04-27 13:05:37 +0530 | [diff] [blame] | 71 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 72 | unlock: |
| 73 | mutex_unlock(&priv->htc_pm_lock); |
| 74 | } |
| 75 | |
| 76 | void ath9k_ps_work(struct work_struct *work) |
| 77 | { |
| 78 | struct ath9k_htc_priv *priv = |
| 79 | container_of(work, struct ath9k_htc_priv, |
| 80 | ps_work); |
| 81 | ath9k_htc_setpower(priv, ATH9K_PM_AWAKE); |
| 82 | |
| 83 | /* The chip wakes up after receiving the first beacon |
| 84 | while network sleep is enabled. For the driver to |
| 85 | be in sync with the hw, set the chip to awake and |
| 86 | only then set it to sleep. |
| 87 | */ |
| 88 | ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP); |
| 89 | } |
| 90 | |
Sujith Manoharan | 7c27734 | 2011-02-21 07:48:39 +0530 | [diff] [blame] | 91 | static void ath9k_htc_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif) |
| 92 | { |
| 93 | struct ath9k_htc_priv *priv = data; |
| 94 | struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; |
| 95 | |
Javier Cardona | 594e65b | 2013-05-08 10:16:46 -0700 | [diff] [blame] | 96 | if ((vif->type == NL80211_IFTYPE_AP || |
| 97 | vif->type == NL80211_IFTYPE_MESH_POINT) && |
| 98 | bss_conf->enable_beacon) |
Sujith Manoharan | a5fae37 | 2011-02-21 07:49:53 +0530 | [diff] [blame] | 99 | priv->reconfig_beacon = true; |
| 100 | |
Sujith Manoharan | 7c27734 | 2011-02-21 07:48:39 +0530 | [diff] [blame] | 101 | if (bss_conf->assoc) { |
| 102 | priv->rearm_ani = true; |
| 103 | priv->reconfig_beacon = true; |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | static void ath9k_htc_vif_reconfig(struct ath9k_htc_priv *priv) |
| 108 | { |
| 109 | priv->rearm_ani = false; |
| 110 | priv->reconfig_beacon = false; |
| 111 | |
Johannes Berg | 8b2c982 | 2012-11-06 20:23:30 +0100 | [diff] [blame] | 112 | ieee80211_iterate_active_interfaces_atomic( |
| 113 | priv->hw, IEEE80211_IFACE_ITER_RESUME_ALL, |
| 114 | ath9k_htc_vif_iter, priv); |
Sujith Manoharan | 7c27734 | 2011-02-21 07:48:39 +0530 | [diff] [blame] | 115 | if (priv->rearm_ani) |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 116 | ath9k_htc_start_ani(priv); |
Sujith Manoharan | 7c27734 | 2011-02-21 07:48:39 +0530 | [diff] [blame] | 117 | |
| 118 | if (priv->reconfig_beacon) { |
| 119 | ath9k_htc_ps_wakeup(priv); |
| 120 | ath9k_htc_beacon_reconfig(priv); |
| 121 | ath9k_htc_ps_restore(priv); |
| 122 | } |
| 123 | } |
| 124 | |
Sujith Manoharan | 585895c | 2011-02-21 07:48:46 +0530 | [diff] [blame] | 125 | static void ath9k_htc_bssid_iter(void *data, u8 *mac, struct ieee80211_vif *vif) |
| 126 | { |
| 127 | struct ath9k_vif_iter_data *iter_data = data; |
| 128 | int i; |
| 129 | |
Mathy Vanhoef | 657eb17 | 2013-11-28 12:21:45 +0100 | [diff] [blame] | 130 | if (iter_data->hw_macaddr != NULL) { |
| 131 | for (i = 0; i < ETH_ALEN; i++) |
| 132 | iter_data->mask[i] &= ~(iter_data->hw_macaddr[i] ^ mac[i]); |
| 133 | } else { |
| 134 | iter_data->hw_macaddr = mac; |
| 135 | } |
Sujith Manoharan | 585895c | 2011-02-21 07:48:46 +0530 | [diff] [blame] | 136 | } |
| 137 | |
Mathy Vanhoef | 657eb17 | 2013-11-28 12:21:45 +0100 | [diff] [blame] | 138 | static void ath9k_htc_set_mac_bssid_mask(struct ath9k_htc_priv *priv, |
Sujith Manoharan | 585895c | 2011-02-21 07:48:46 +0530 | [diff] [blame] | 139 | struct ieee80211_vif *vif) |
| 140 | { |
| 141 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 142 | struct ath9k_vif_iter_data iter_data; |
| 143 | |
| 144 | /* |
Mathy Vanhoef | 657eb17 | 2013-11-28 12:21:45 +0100 | [diff] [blame] | 145 | * Pick the MAC address of the first interface as the new hardware |
| 146 | * MAC address. The hardware will use it together with the BSSID mask |
| 147 | * when matching addresses. |
Sujith Manoharan | 585895c | 2011-02-21 07:48:46 +0530 | [diff] [blame] | 148 | */ |
Mathy Vanhoef | 657eb17 | 2013-11-28 12:21:45 +0100 | [diff] [blame] | 149 | iter_data.hw_macaddr = NULL; |
Sujith Manoharan | 585895c | 2011-02-21 07:48:46 +0530 | [diff] [blame] | 150 | memset(&iter_data.mask, 0xff, ETH_ALEN); |
| 151 | |
| 152 | if (vif) |
| 153 | ath9k_htc_bssid_iter(&iter_data, vif->addr, vif); |
| 154 | |
| 155 | /* Get list of all active MAC addresses */ |
Johannes Berg | 8b2c982 | 2012-11-06 20:23:30 +0100 | [diff] [blame] | 156 | ieee80211_iterate_active_interfaces_atomic( |
| 157 | priv->hw, IEEE80211_IFACE_ITER_RESUME_ALL, |
| 158 | ath9k_htc_bssid_iter, &iter_data); |
Sujith Manoharan | 585895c | 2011-02-21 07:48:46 +0530 | [diff] [blame] | 159 | |
| 160 | memcpy(common->bssidmask, iter_data.mask, ETH_ALEN); |
Mathy Vanhoef | 657eb17 | 2013-11-28 12:21:45 +0100 | [diff] [blame] | 161 | |
| 162 | if (iter_data.hw_macaddr) |
| 163 | memcpy(common->macaddr, iter_data.hw_macaddr, ETH_ALEN); |
| 164 | |
Sujith Manoharan | 585895c | 2011-02-21 07:48:46 +0530 | [diff] [blame] | 165 | ath_hw_setbssidmask(common); |
| 166 | } |
| 167 | |
Sujith Manoharan | ffbe7c8 | 2011-02-21 07:49:31 +0530 | [diff] [blame] | 168 | static void ath9k_htc_set_opmode(struct ath9k_htc_priv *priv) |
| 169 | { |
| 170 | if (priv->num_ibss_vif) |
| 171 | priv->ah->opmode = NL80211_IFTYPE_ADHOC; |
| 172 | else if (priv->num_ap_vif) |
| 173 | priv->ah->opmode = NL80211_IFTYPE_AP; |
Javier Cardona | 594e65b | 2013-05-08 10:16:46 -0700 | [diff] [blame] | 174 | else if (priv->num_mbss_vif) |
| 175 | priv->ah->opmode = NL80211_IFTYPE_MESH_POINT; |
Sujith Manoharan | ffbe7c8 | 2011-02-21 07:49:31 +0530 | [diff] [blame] | 176 | else |
| 177 | priv->ah->opmode = NL80211_IFTYPE_STATION; |
| 178 | |
| 179 | ath9k_hw_setopmode(priv->ah); |
| 180 | } |
| 181 | |
Sujith Manoharan | 7390867 | 2010-12-28 14:28:27 +0530 | [diff] [blame] | 182 | void ath9k_htc_reset(struct ath9k_htc_priv *priv) |
| 183 | { |
| 184 | struct ath_hw *ah = priv->ah; |
| 185 | struct ath_common *common = ath9k_hw_common(ah); |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 186 | struct ieee80211_channel *channel = priv->hw->conf.chandef.chan; |
Rajkumar Manoharan | 4e3ae38 | 2011-01-15 01:33:28 +0530 | [diff] [blame] | 187 | struct ath9k_hw_cal_data *caldata = NULL; |
Sujith Manoharan | 7390867 | 2010-12-28 14:28:27 +0530 | [diff] [blame] | 188 | enum htc_phymode mode; |
| 189 | __be16 htc_mode; |
| 190 | u8 cmd_rsp; |
| 191 | int ret; |
| 192 | |
| 193 | mutex_lock(&priv->mutex); |
| 194 | ath9k_htc_ps_wakeup(priv); |
| 195 | |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 196 | ath9k_htc_stop_ani(priv); |
Sujith Manoharan | 7390867 | 2010-12-28 14:28:27 +0530 | [diff] [blame] | 197 | ieee80211_stop_queues(priv->hw); |
Sujith Manoharan | b587fc8 | 2011-04-13 11:25:59 +0530 | [diff] [blame] | 198 | |
Sujith Manoharan | 859c3ca | 2011-04-13 11:26:39 +0530 | [diff] [blame] | 199 | del_timer_sync(&priv->tx.cleanup_timer); |
Sujith Manoharan | b587fc8 | 2011-04-13 11:25:59 +0530 | [diff] [blame] | 200 | ath9k_htc_tx_drain(priv); |
| 201 | |
Sujith Manoharan | 7390867 | 2010-12-28 14:28:27 +0530 | [diff] [blame] | 202 | WMI_CMD(WMI_DISABLE_INTR_CMDID); |
| 203 | WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID); |
| 204 | WMI_CMD(WMI_STOP_RECV_CMDID); |
| 205 | |
Sujith Manoharan | f4c8899 | 2011-04-13 11:23:52 +0530 | [diff] [blame] | 206 | ath9k_wmi_event_drain(priv); |
| 207 | |
Rajkumar Manoharan | 4e3ae38 | 2011-01-15 01:33:28 +0530 | [diff] [blame] | 208 | caldata = &priv->caldata; |
Sujith Manoharan | 7390867 | 2010-12-28 14:28:27 +0530 | [diff] [blame] | 209 | ret = ath9k_hw_reset(ah, ah->curchan, caldata, false); |
| 210 | if (ret) { |
| 211 | ath_err(common, |
| 212 | "Unable to reset device (%u Mhz) reset status %d\n", |
| 213 | channel->center_freq, ret); |
| 214 | } |
| 215 | |
Rajkumar Manoharan | b2a5c3d | 2011-01-31 23:47:45 +0530 | [diff] [blame] | 216 | ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit, |
| 217 | &priv->curtxpow); |
Sujith Manoharan | 7390867 | 2010-12-28 14:28:27 +0530 | [diff] [blame] | 218 | |
| 219 | WMI_CMD(WMI_START_RECV_CMDID); |
| 220 | ath9k_host_rx_init(priv); |
| 221 | |
| 222 | mode = ath9k_htc_get_curmode(priv, ah->curchan); |
| 223 | htc_mode = cpu_to_be16(mode); |
| 224 | WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode); |
| 225 | |
| 226 | WMI_CMD(WMI_ENABLE_INTR_CMDID); |
| 227 | htc_start(priv->htc); |
Sujith Manoharan | 7c27734 | 2011-02-21 07:48:39 +0530 | [diff] [blame] | 228 | ath9k_htc_vif_reconfig(priv); |
Sujith Manoharan | 7390867 | 2010-12-28 14:28:27 +0530 | [diff] [blame] | 229 | ieee80211_wake_queues(priv->hw); |
| 230 | |
Sujith Manoharan | 859c3ca | 2011-04-13 11:26:39 +0530 | [diff] [blame] | 231 | mod_timer(&priv->tx.cleanup_timer, |
| 232 | jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL)); |
| 233 | |
Sujith Manoharan | 7390867 | 2010-12-28 14:28:27 +0530 | [diff] [blame] | 234 | ath9k_htc_ps_restore(priv); |
| 235 | mutex_unlock(&priv->mutex); |
| 236 | } |
| 237 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 238 | static int ath9k_htc_set_channel(struct ath9k_htc_priv *priv, |
| 239 | struct ieee80211_hw *hw, |
| 240 | struct ath9k_channel *hchan) |
| 241 | { |
| 242 | struct ath_hw *ah = priv->ah; |
| 243 | struct ath_common *common = ath9k_hw_common(ah); |
| 244 | struct ieee80211_conf *conf = &common->hw->conf; |
Sujith Manoharan | 039a072 | 2010-12-28 14:28:37 +0530 | [diff] [blame] | 245 | bool fastcc; |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 246 | struct ieee80211_channel *channel = hw->conf.chandef.chan; |
Vivek Natarajan | 8354dd3 | 2011-02-18 16:09:51 +0530 | [diff] [blame] | 247 | struct ath9k_hw_cal_data *caldata = NULL; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 248 | enum htc_phymode mode; |
Sujith | 7f1f5a0 | 2010-04-16 11:54:03 +0530 | [diff] [blame] | 249 | __be16 htc_mode; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 250 | u8 cmd_rsp; |
| 251 | int ret; |
| 252 | |
Sujith Manoharan | d8a2c51 | 2012-06-25 13:54:41 +0530 | [diff] [blame] | 253 | if (test_bit(OP_INVALID, &priv->op_flags)) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 254 | return -EIO; |
| 255 | |
Sujith Manoharan | 039a072 | 2010-12-28 14:28:37 +0530 | [diff] [blame] | 256 | fastcc = !!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 257 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 258 | ath9k_htc_ps_wakeup(priv); |
Sujith Manoharan | b587fc8 | 2011-04-13 11:25:59 +0530 | [diff] [blame] | 259 | |
Sujith Manoharan | 859c3ca | 2011-04-13 11:26:39 +0530 | [diff] [blame] | 260 | del_timer_sync(&priv->tx.cleanup_timer); |
Sujith Manoharan | b587fc8 | 2011-04-13 11:25:59 +0530 | [diff] [blame] | 261 | ath9k_htc_tx_drain(priv); |
| 262 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 263 | WMI_CMD(WMI_DISABLE_INTR_CMDID); |
| 264 | WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID); |
| 265 | WMI_CMD(WMI_STOP_RECV_CMDID); |
| 266 | |
Sujith Manoharan | f4c8899 | 2011-04-13 11:23:52 +0530 | [diff] [blame] | 267 | ath9k_wmi_event_drain(priv); |
| 268 | |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 269 | ath_dbg(common, CONFIG, |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 270 | "(%u MHz) -> (%u MHz), HT: %d, HT40: %d fastcc: %d\n", |
| 271 | priv->ah->curchan->channel, |
| 272 | channel->center_freq, conf_is_ht(conf), conf_is_ht40(conf), |
| 273 | fastcc); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 274 | |
Rajkumar Manoharan | 4e3ae38 | 2011-01-15 01:33:28 +0530 | [diff] [blame] | 275 | if (!fastcc) |
| 276 | caldata = &priv->caldata; |
Sujith Manoharan | b587fc8 | 2011-04-13 11:25:59 +0530 | [diff] [blame] | 277 | |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 278 | ret = ath9k_hw_reset(ah, hchan, caldata, fastcc); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 279 | if (ret) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 280 | ath_err(common, |
| 281 | "Unable to reset channel (%u Mhz) reset status %d\n", |
| 282 | channel->center_freq, ret); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 283 | goto err; |
| 284 | } |
| 285 | |
Rajkumar Manoharan | b2a5c3d | 2011-01-31 23:47:45 +0530 | [diff] [blame] | 286 | ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit, |
| 287 | &priv->curtxpow); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 288 | |
| 289 | WMI_CMD(WMI_START_RECV_CMDID); |
| 290 | if (ret) |
| 291 | goto err; |
| 292 | |
| 293 | ath9k_host_rx_init(priv); |
| 294 | |
| 295 | mode = ath9k_htc_get_curmode(priv, hchan); |
| 296 | htc_mode = cpu_to_be16(mode); |
| 297 | WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode); |
| 298 | if (ret) |
| 299 | goto err; |
| 300 | |
| 301 | WMI_CMD(WMI_ENABLE_INTR_CMDID); |
| 302 | if (ret) |
| 303 | goto err; |
| 304 | |
| 305 | htc_start(priv->htc); |
Sujith Manoharan | a5fae37 | 2011-02-21 07:49:53 +0530 | [diff] [blame] | 306 | |
Sujith Manoharan | d8a2c51 | 2012-06-25 13:54:41 +0530 | [diff] [blame] | 307 | if (!test_bit(OP_SCANNING, &priv->op_flags) && |
Sujith Manoharan | a5fae37 | 2011-02-21 07:49:53 +0530 | [diff] [blame] | 308 | !(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)) |
| 309 | ath9k_htc_vif_reconfig(priv); |
| 310 | |
Sujith Manoharan | 859c3ca | 2011-04-13 11:26:39 +0530 | [diff] [blame] | 311 | mod_timer(&priv->tx.cleanup_timer, |
| 312 | jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL)); |
| 313 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 314 | err: |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 315 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 316 | return ret; |
| 317 | } |
| 318 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 319 | /* |
| 320 | * Monitor mode handling is a tad complicated because the firmware requires |
| 321 | * an interface to be created exclusively, while mac80211 doesn't associate |
| 322 | * an interface with the mode. |
| 323 | * |
| 324 | * So, for now, only one monitor interface can be configured. |
| 325 | */ |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 326 | static void __ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv) |
Rajkumar Manoharan | 81fc2a3 | 2010-11-26 23:24:33 +0530 | [diff] [blame] | 327 | { |
| 328 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 329 | struct ath9k_htc_target_vif hvif; |
| 330 | int ret = 0; |
| 331 | u8 cmd_rsp; |
| 332 | |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 333 | memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif)); |
| 334 | memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN); |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 335 | hvif.index = priv->mon_vif_idx; |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 336 | WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif); |
Sujith Manoharan | 0ff2b5c | 2011-04-20 11:00:34 +0530 | [diff] [blame] | 337 | if (ret) { |
| 338 | ath_err(common, "Unable to remove monitor interface at idx: %d\n", |
| 339 | priv->mon_vif_idx); |
| 340 | } |
| 341 | |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 342 | priv->nvifs--; |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 343 | priv->vif_slot &= ~(1 << priv->mon_vif_idx); |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | static int ath9k_htc_add_monitor_interface(struct ath9k_htc_priv *priv) |
| 347 | { |
| 348 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 349 | struct ath9k_htc_target_vif hvif; |
| 350 | struct ath9k_htc_target_sta tsta; |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 351 | int ret = 0, sta_idx; |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 352 | u8 cmd_rsp; |
| 353 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 354 | if ((priv->nvifs >= ATH9K_HTC_MAX_VIF) || |
| 355 | (priv->nstations >= ATH9K_HTC_MAX_STA)) { |
| 356 | ret = -ENOBUFS; |
| 357 | goto err_vif; |
| 358 | } |
Rajkumar Manoharan | 81fc2a3 | 2010-11-26 23:24:33 +0530 | [diff] [blame] | 359 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 360 | sta_idx = ffz(priv->sta_slot); |
| 361 | if ((sta_idx < 0) || (sta_idx > ATH9K_HTC_MAX_STA)) { |
| 362 | ret = -ENOBUFS; |
| 363 | goto err_vif; |
| 364 | } |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 365 | |
| 366 | /* |
| 367 | * Add an interface. |
| 368 | */ |
Rajkumar Manoharan | 81fc2a3 | 2010-11-26 23:24:33 +0530 | [diff] [blame] | 369 | memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif)); |
| 370 | memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN); |
| 371 | |
Sujith Manoharan | e4c6250 | 2011-04-13 11:24:43 +0530 | [diff] [blame] | 372 | hvif.opmode = HTC_M_MONITOR; |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 373 | hvif.index = ffz(priv->vif_slot); |
Rajkumar Manoharan | 81fc2a3 | 2010-11-26 23:24:33 +0530 | [diff] [blame] | 374 | |
| 375 | WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif); |
| 376 | if (ret) |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 377 | goto err_vif; |
| 378 | |
| 379 | /* |
| 380 | * Assign the monitor interface index as a special case here. |
| 381 | * This is needed when the interface is brought down. |
| 382 | */ |
| 383 | priv->mon_vif_idx = hvif.index; |
| 384 | priv->vif_slot |= (1 << hvif.index); |
| 385 | |
| 386 | /* |
| 387 | * Set the hardware mode to monitor only if there are no |
| 388 | * other interfaces. |
| 389 | */ |
| 390 | if (!priv->nvifs) |
| 391 | priv->ah->opmode = NL80211_IFTYPE_MONITOR; |
Rajkumar Manoharan | 81fc2a3 | 2010-11-26 23:24:33 +0530 | [diff] [blame] | 392 | |
| 393 | priv->nvifs++; |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 394 | |
| 395 | /* |
| 396 | * Associate a station with the interface for packet injection. |
| 397 | */ |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 398 | memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta)); |
| 399 | |
| 400 | memcpy(&tsta.macaddr, common->macaddr, ETH_ALEN); |
| 401 | |
| 402 | tsta.is_vif_sta = 1; |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 403 | tsta.sta_index = sta_idx; |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 404 | tsta.vif_index = hvif.index; |
Sujith Manoharan | b97c57f | 2011-04-13 11:24:37 +0530 | [diff] [blame] | 405 | tsta.maxampdu = cpu_to_be16(0xffff); |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 406 | |
| 407 | WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta); |
| 408 | if (ret) { |
| 409 | ath_err(common, "Unable to add station entry for monitor mode\n"); |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 410 | goto err_sta; |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 411 | } |
| 412 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 413 | priv->sta_slot |= (1 << sta_idx); |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 414 | priv->nstations++; |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 415 | priv->vif_sta_pos[priv->mon_vif_idx] = sta_idx; |
Sujith Manoharan | 55de80d | 2011-01-05 01:06:21 +0530 | [diff] [blame] | 416 | priv->ah->is_monitoring = true; |
| 417 | |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 418 | ath_dbg(common, CONFIG, |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 419 | "Attached a monitor interface at idx: %d, sta idx: %d\n", |
| 420 | priv->mon_vif_idx, sta_idx); |
| 421 | |
Rajkumar Manoharan | 81fc2a3 | 2010-11-26 23:24:33 +0530 | [diff] [blame] | 422 | return 0; |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 423 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 424 | err_sta: |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 425 | /* |
| 426 | * Remove the interface from the target. |
| 427 | */ |
| 428 | __ath9k_htc_remove_monitor_interface(priv); |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 429 | err_vif: |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 430 | ath_dbg(common, FATAL, "Unable to attach a monitor interface\n"); |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 431 | |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 432 | return ret; |
Rajkumar Manoharan | 81fc2a3 | 2010-11-26 23:24:33 +0530 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | static int ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv) |
| 436 | { |
| 437 | struct ath_common *common = ath9k_hw_common(priv->ah); |
Rajkumar Manoharan | 81fc2a3 | 2010-11-26 23:24:33 +0530 | [diff] [blame] | 438 | int ret = 0; |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 439 | u8 cmd_rsp, sta_idx; |
Rajkumar Manoharan | 81fc2a3 | 2010-11-26 23:24:33 +0530 | [diff] [blame] | 440 | |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 441 | __ath9k_htc_remove_monitor_interface(priv); |
Rajkumar Manoharan | 81fc2a3 | 2010-11-26 23:24:33 +0530 | [diff] [blame] | 442 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 443 | sta_idx = priv->vif_sta_pos[priv->mon_vif_idx]; |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 444 | |
| 445 | WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx); |
| 446 | if (ret) { |
| 447 | ath_err(common, "Unable to remove station entry for monitor mode\n"); |
| 448 | return ret; |
| 449 | } |
| 450 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 451 | priv->sta_slot &= ~(1 << sta_idx); |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 452 | priv->nstations--; |
Sujith Manoharan | 55de80d | 2011-01-05 01:06:21 +0530 | [diff] [blame] | 453 | priv->ah->is_monitoring = false; |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 454 | |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 455 | ath_dbg(common, CONFIG, |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 456 | "Removed a monitor interface at idx: %d, sta idx: %d\n", |
| 457 | priv->mon_vif_idx, sta_idx); |
| 458 | |
Sujith Manoharan | cc72128 | 2011-01-03 21:22:18 +0530 | [diff] [blame] | 459 | return 0; |
Rajkumar Manoharan | 81fc2a3 | 2010-11-26 23:24:33 +0530 | [diff] [blame] | 460 | } |
| 461 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 462 | static int ath9k_htc_add_station(struct ath9k_htc_priv *priv, |
| 463 | struct ieee80211_vif *vif, |
| 464 | struct ieee80211_sta *sta) |
| 465 | { |
| 466 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 467 | struct ath9k_htc_target_sta tsta; |
| 468 | struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv; |
| 469 | struct ath9k_htc_sta *ista; |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 470 | int ret, sta_idx; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 471 | u8 cmd_rsp; |
Sujith Manoharan | f0dd498 | 2011-04-20 11:01:00 +0530 | [diff] [blame] | 472 | u16 maxampdu; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 473 | |
| 474 | if (priv->nstations >= ATH9K_HTC_MAX_STA) |
| 475 | return -ENOBUFS; |
| 476 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 477 | sta_idx = ffz(priv->sta_slot); |
| 478 | if ((sta_idx < 0) || (sta_idx > ATH9K_HTC_MAX_STA)) |
| 479 | return -ENOBUFS; |
| 480 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 481 | memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta)); |
| 482 | |
| 483 | if (sta) { |
| 484 | ista = (struct ath9k_htc_sta *) sta->drv_priv; |
| 485 | memcpy(&tsta.macaddr, sta->addr, ETH_ALEN); |
| 486 | memcpy(&tsta.bssid, common->curbssid, ETH_ALEN); |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 487 | ista->index = sta_idx; |
Mohammed Shafi Shajakhan | fed27f6 | 2012-09-04 19:33:37 +0530 | [diff] [blame] | 488 | tsta.is_vif_sta = 0; |
| 489 | maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR + |
| 490 | sta->ht_cap.ampdu_factor); |
| 491 | tsta.maxampdu = cpu_to_be16(maxampdu); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 492 | } else { |
| 493 | memcpy(&tsta.macaddr, vif->addr, ETH_ALEN); |
| 494 | tsta.is_vif_sta = 1; |
Mohammed Shafi Shajakhan | fed27f6 | 2012-09-04 19:33:37 +0530 | [diff] [blame] | 495 | tsta.maxampdu = cpu_to_be16(0xffff); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 496 | } |
| 497 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 498 | tsta.sta_index = sta_idx; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 499 | tsta.vif_index = avp->index; |
Sujith Manoharan | f0dd498 | 2011-04-20 11:01:00 +0530 | [diff] [blame] | 500 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 501 | WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta); |
| 502 | if (ret) { |
| 503 | if (sta) |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 504 | ath_err(common, |
| 505 | "Unable to add station entry for: %pM\n", |
| 506 | sta->addr); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 507 | return ret; |
| 508 | } |
| 509 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 510 | if (sta) { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 511 | ath_dbg(common, CONFIG, |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 512 | "Added a station entry for: %pM (idx: %d)\n", |
| 513 | sta->addr, tsta.sta_index); |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 514 | } else { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 515 | ath_dbg(common, CONFIG, |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 516 | "Added a station entry for VIF %d (idx: %d)\n", |
| 517 | avp->index, tsta.sta_index); |
| 518 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 519 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 520 | priv->sta_slot |= (1 << sta_idx); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 521 | priv->nstations++; |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 522 | if (!sta) |
| 523 | priv->vif_sta_pos[avp->index] = sta_idx; |
| 524 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 525 | return 0; |
| 526 | } |
| 527 | |
| 528 | static int ath9k_htc_remove_station(struct ath9k_htc_priv *priv, |
| 529 | struct ieee80211_vif *vif, |
| 530 | struct ieee80211_sta *sta) |
| 531 | { |
| 532 | struct ath_common *common = ath9k_hw_common(priv->ah); |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 533 | struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 534 | struct ath9k_htc_sta *ista; |
| 535 | int ret; |
| 536 | u8 cmd_rsp, sta_idx; |
| 537 | |
| 538 | if (sta) { |
| 539 | ista = (struct ath9k_htc_sta *) sta->drv_priv; |
| 540 | sta_idx = ista->index; |
| 541 | } else { |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 542 | sta_idx = priv->vif_sta_pos[avp->index]; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx); |
| 546 | if (ret) { |
| 547 | if (sta) |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 548 | ath_err(common, |
| 549 | "Unable to remove station entry for: %pM\n", |
| 550 | sta->addr); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 551 | return ret; |
| 552 | } |
| 553 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 554 | if (sta) { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 555 | ath_dbg(common, CONFIG, |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 556 | "Removed a station entry for: %pM (idx: %d)\n", |
| 557 | sta->addr, sta_idx); |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 558 | } else { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 559 | ath_dbg(common, CONFIG, |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 560 | "Removed a station entry for VIF %d (idx: %d)\n", |
| 561 | avp->index, sta_idx); |
| 562 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 563 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 564 | priv->sta_slot &= ~(1 << sta_idx); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 565 | priv->nstations--; |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 566 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 567 | return 0; |
| 568 | } |
| 569 | |
Sujith Manoharan | 3a0593e | 2011-04-20 14:33:28 +0530 | [diff] [blame] | 570 | int ath9k_htc_update_cap_target(struct ath9k_htc_priv *priv, |
| 571 | u8 enable_coex) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 572 | { |
| 573 | struct ath9k_htc_cap_target tcap; |
| 574 | int ret; |
| 575 | u8 cmd_rsp; |
| 576 | |
| 577 | memset(&tcap, 0, sizeof(struct ath9k_htc_cap_target)); |
| 578 | |
Sujith Manoharan | 3a0593e | 2011-04-20 14:33:28 +0530 | [diff] [blame] | 579 | tcap.ampdu_limit = cpu_to_be32(0xffff); |
Sujith Manoharan | bd54879 | 2011-05-17 12:42:14 +0530 | [diff] [blame] | 580 | tcap.ampdu_subframes = 0xff; |
Sujith Manoharan | 3a0593e | 2011-04-20 14:33:28 +0530 | [diff] [blame] | 581 | tcap.enable_coex = enable_coex; |
Sujith | 29d9075 | 2010-06-02 15:53:43 +0530 | [diff] [blame] | 582 | tcap.tx_chainmask = priv->ah->caps.tx_chainmask; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 583 | |
| 584 | WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID, &tcap); |
| 585 | |
| 586 | return ret; |
| 587 | } |
| 588 | |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 589 | static void ath9k_htc_setup_rate(struct ath9k_htc_priv *priv, |
| 590 | struct ieee80211_sta *sta, |
| 591 | struct ath9k_htc_target_rate *trate) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 592 | { |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 593 | struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv; |
| 594 | struct ieee80211_supported_band *sband; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 595 | u32 caps = 0; |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 596 | int i, j; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 597 | |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 598 | sband = priv->hw->wiphy->bands[priv->hw->conf.chandef.chan->band]; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 599 | |
| 600 | for (i = 0, j = 0; i < sband->n_bitrates; i++) { |
| 601 | if (sta->supp_rates[sband->band] & BIT(i)) { |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 602 | trate->rates.legacy_rates.rs_rates[j] |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 603 | = (sband->bitrates[i].bitrate * 2) / 10; |
| 604 | j++; |
| 605 | } |
| 606 | } |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 607 | trate->rates.legacy_rates.rs_nrates = j; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 608 | |
| 609 | if (sta->ht_cap.ht_supported) { |
| 610 | for (i = 0, j = 0; i < 77; i++) { |
| 611 | if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8))) |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 612 | trate->rates.ht_rates.rs_rates[j++] = i; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 613 | if (j == ATH_HTC_RATE_MAX) |
| 614 | break; |
| 615 | } |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 616 | trate->rates.ht_rates.rs_nrates = j; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 617 | |
| 618 | caps = WLAN_RC_HT_FLAG; |
Oleksij Rempel | a226c3d | 2013-06-09 18:51:24 +0200 | [diff] [blame] | 619 | if (sta->ht_cap.cap & IEEE80211_HT_CAP_RX_STBC) |
| 620 | caps |= ATH_RC_TX_STBC_FLAG; |
Felix Fietkau | 3553727 | 2010-06-12 17:22:33 +0200 | [diff] [blame] | 621 | if (sta->ht_cap.mcs.rx_mask[1]) |
| 622 | caps |= WLAN_RC_DS_FLAG; |
Vivek Natarajan | 71ba186 | 2010-08-12 14:23:28 +0530 | [diff] [blame] | 623 | if ((sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) && |
| 624 | (conf_is_ht40(&priv->hw->conf))) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 625 | caps |= WLAN_RC_40_FLAG; |
Sujith | b4dec5e | 2010-05-17 12:01:19 +0530 | [diff] [blame] | 626 | if (conf_is_ht40(&priv->hw->conf) && |
| 627 | (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40)) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 628 | caps |= WLAN_RC_SGI_FLAG; |
Sujith | b4dec5e | 2010-05-17 12:01:19 +0530 | [diff] [blame] | 629 | else if (conf_is_ht20(&priv->hw->conf) && |
| 630 | (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20)) |
| 631 | caps |= WLAN_RC_SGI_FLAG; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 632 | } |
| 633 | |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 634 | trate->sta_index = ista->index; |
| 635 | trate->isnew = 1; |
| 636 | trate->capflags = cpu_to_be32(caps); |
| 637 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 638 | |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 639 | static int ath9k_htc_send_rate_cmd(struct ath9k_htc_priv *priv, |
| 640 | struct ath9k_htc_target_rate *trate) |
| 641 | { |
| 642 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 643 | int ret; |
| 644 | u8 cmd_rsp; |
| 645 | |
| 646 | WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID, trate); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 647 | if (ret) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 648 | ath_err(common, |
| 649 | "Unable to initialize Rate information on target\n"); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 650 | } |
| 651 | |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 652 | return ret; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 653 | } |
| 654 | |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 655 | static void ath9k_htc_init_rate(struct ath9k_htc_priv *priv, |
| 656 | struct ieee80211_sta *sta) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 657 | { |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 658 | struct ath_common *common = ath9k_hw_common(priv->ah); |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 659 | struct ath9k_htc_target_rate trate; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 660 | int ret; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 661 | |
Sujith | 0d425a7 | 2010-05-17 12:01:16 +0530 | [diff] [blame] | 662 | memset(&trate, 0, sizeof(struct ath9k_htc_target_rate)); |
| 663 | ath9k_htc_setup_rate(priv, sta, &trate); |
| 664 | ret = ath9k_htc_send_rate_cmd(priv, &trate); |
| 665 | if (!ret) |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 666 | ath_dbg(common, CONFIG, |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 667 | "Updated target sta: %pM, rate caps: 0x%X\n", |
| 668 | sta->addr, be32_to_cpu(trate.capflags)); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 669 | } |
| 670 | |
Sujith | 2c76ef8 | 2010-05-17 12:01:18 +0530 | [diff] [blame] | 671 | static void ath9k_htc_update_rate(struct ath9k_htc_priv *priv, |
| 672 | struct ieee80211_vif *vif, |
| 673 | struct ieee80211_bss_conf *bss_conf) |
| 674 | { |
| 675 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 676 | struct ath9k_htc_target_rate trate; |
| 677 | struct ieee80211_sta *sta; |
| 678 | int ret; |
| 679 | |
| 680 | memset(&trate, 0, sizeof(struct ath9k_htc_target_rate)); |
| 681 | |
| 682 | rcu_read_lock(); |
| 683 | sta = ieee80211_find_sta(vif, bss_conf->bssid); |
| 684 | if (!sta) { |
| 685 | rcu_read_unlock(); |
| 686 | return; |
| 687 | } |
| 688 | ath9k_htc_setup_rate(priv, sta, &trate); |
| 689 | rcu_read_unlock(); |
| 690 | |
| 691 | ret = ath9k_htc_send_rate_cmd(priv, &trate); |
| 692 | if (!ret) |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 693 | ath_dbg(common, CONFIG, |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 694 | "Updated target sta: %pM, rate caps: 0x%X\n", |
| 695 | bss_conf->bssid, be32_to_cpu(trate.capflags)); |
Sujith | 2c76ef8 | 2010-05-17 12:01:18 +0530 | [diff] [blame] | 696 | } |
| 697 | |
Luis R. Rodriguez | 9edd952 | 2010-07-13 21:27:25 -0400 | [diff] [blame] | 698 | static int ath9k_htc_tx_aggr_oper(struct ath9k_htc_priv *priv, |
| 699 | struct ieee80211_vif *vif, |
| 700 | struct ieee80211_sta *sta, |
| 701 | enum ieee80211_ampdu_mlme_action action, |
| 702 | u16 tid) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 703 | { |
| 704 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 705 | struct ath9k_htc_target_aggr aggr; |
Dan Carpenter | 277a64d | 2010-05-08 18:23:20 +0200 | [diff] [blame] | 706 | struct ath9k_htc_sta *ista; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 707 | int ret = 0; |
| 708 | u8 cmd_rsp; |
| 709 | |
Dan Carpenter | 0730d11 | 2010-05-08 18:24:02 +0200 | [diff] [blame] | 710 | if (tid >= ATH9K_HTC_MAX_TID) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 711 | return -EINVAL; |
| 712 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 713 | memset(&aggr, 0, sizeof(struct ath9k_htc_target_aggr)); |
Sujith | ef98c3c | 2010-03-29 16:07:11 +0530 | [diff] [blame] | 714 | ista = (struct ath9k_htc_sta *) sta->drv_priv; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 715 | |
Sujith | ef98c3c | 2010-03-29 16:07:11 +0530 | [diff] [blame] | 716 | aggr.sta_index = ista->index; |
Sujith | d7ca213 | 2010-06-15 10:24:37 +0530 | [diff] [blame] | 717 | aggr.tidno = tid & 0xf; |
| 718 | aggr.aggr_enable = (action == IEEE80211_AMPDU_TX_START) ? true : false; |
Sujith | ef98c3c | 2010-03-29 16:07:11 +0530 | [diff] [blame] | 719 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 720 | WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID, &aggr); |
| 721 | if (ret) |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 722 | ath_dbg(common, CONFIG, |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 723 | "Unable to %s TX aggregation for (%pM, %d)\n", |
| 724 | (aggr.aggr_enable) ? "start" : "stop", sta->addr, tid); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 725 | else |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 726 | ath_dbg(common, CONFIG, |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 727 | "%s TX aggregation for (%pM, %d)\n", |
| 728 | (aggr.aggr_enable) ? "Starting" : "Stopping", |
| 729 | sta->addr, tid); |
Sujith | d7ca213 | 2010-06-15 10:24:37 +0530 | [diff] [blame] | 730 | |
Sujith Manoharan | 658ef04 | 2011-04-13 11:25:00 +0530 | [diff] [blame] | 731 | spin_lock_bh(&priv->tx.tx_lock); |
Sujith | d7ca213 | 2010-06-15 10:24:37 +0530 | [diff] [blame] | 732 | ista->tid_state[tid] = (aggr.aggr_enable && !ret) ? AGGR_START : AGGR_STOP; |
Sujith Manoharan | 658ef04 | 2011-04-13 11:25:00 +0530 | [diff] [blame] | 733 | spin_unlock_bh(&priv->tx.tx_lock); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 734 | |
| 735 | return ret; |
| 736 | } |
| 737 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 738 | /*******/ |
| 739 | /* ANI */ |
| 740 | /*******/ |
| 741 | |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 742 | void ath9k_htc_start_ani(struct ath9k_htc_priv *priv) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 743 | { |
| 744 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 745 | unsigned long timestamp = jiffies_to_msecs(jiffies); |
| 746 | |
| 747 | common->ani.longcal_timer = timestamp; |
| 748 | common->ani.shortcal_timer = timestamp; |
| 749 | common->ani.checkani_timer = timestamp; |
| 750 | |
Sujith Manoharan | d8a2c51 | 2012-06-25 13:54:41 +0530 | [diff] [blame] | 751 | set_bit(OP_ANI_RUNNING, &priv->op_flags); |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 752 | |
| 753 | ieee80211_queue_delayed_work(common->hw, &priv->ani_work, |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 754 | msecs_to_jiffies(ATH_ANI_POLLINTERVAL)); |
| 755 | } |
| 756 | |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 757 | void ath9k_htc_stop_ani(struct ath9k_htc_priv *priv) |
| 758 | { |
| 759 | cancel_delayed_work_sync(&priv->ani_work); |
Sujith Manoharan | d8a2c51 | 2012-06-25 13:54:41 +0530 | [diff] [blame] | 760 | clear_bit(OP_ANI_RUNNING, &priv->op_flags); |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | void ath9k_htc_ani_work(struct work_struct *work) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 764 | { |
| 765 | struct ath9k_htc_priv *priv = |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 766 | container_of(work, struct ath9k_htc_priv, ani_work.work); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 767 | struct ath_hw *ah = priv->ah; |
| 768 | struct ath_common *common = ath9k_hw_common(ah); |
| 769 | bool longcal = false; |
| 770 | bool shortcal = false; |
| 771 | bool aniflag = false; |
| 772 | unsigned int timestamp = jiffies_to_msecs(jiffies); |
| 773 | u32 cal_interval, short_cal_interval; |
| 774 | |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 775 | short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ? |
| 776 | ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 777 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 778 | /* Only calibrate if awake */ |
| 779 | if (ah->power_mode != ATH9K_PM_AWAKE) |
| 780 | goto set_timer; |
| 781 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 782 | /* Long calibration runs independently of short calibration. */ |
| 783 | if ((timestamp - common->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) { |
| 784 | longcal = true; |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 785 | ath_dbg(common, ANI, "longcal @%lu\n", jiffies); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 786 | common->ani.longcal_timer = timestamp; |
| 787 | } |
| 788 | |
| 789 | /* Short calibration applies only while caldone is false */ |
| 790 | if (!common->ani.caldone) { |
| 791 | if ((timestamp - common->ani.shortcal_timer) >= |
| 792 | short_cal_interval) { |
| 793 | shortcal = true; |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 794 | ath_dbg(common, ANI, "shortcal @%lu\n", jiffies); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 795 | common->ani.shortcal_timer = timestamp; |
| 796 | common->ani.resetcal_timer = timestamp; |
| 797 | } |
| 798 | } else { |
| 799 | if ((timestamp - common->ani.resetcal_timer) >= |
| 800 | ATH_RESTART_CALINTERVAL) { |
| 801 | common->ani.caldone = ath9k_hw_reset_calvalid(ah); |
| 802 | if (common->ani.caldone) |
| 803 | common->ani.resetcal_timer = timestamp; |
| 804 | } |
| 805 | } |
| 806 | |
| 807 | /* Verify whether we must check ANI */ |
Sujith Manoharan | e323300 | 2013-06-03 09:19:26 +0530 | [diff] [blame] | 808 | if ((timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) { |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 809 | aniflag = true; |
| 810 | common->ani.checkani_timer = timestamp; |
| 811 | } |
| 812 | |
| 813 | /* Skip all processing if there's nothing to do. */ |
| 814 | if (longcal || shortcal || aniflag) { |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 815 | |
| 816 | ath9k_htc_ps_wakeup(priv); |
| 817 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 818 | /* Call ANI routine if necessary */ |
| 819 | if (aniflag) |
| 820 | ath9k_hw_ani_monitor(ah, ah->curchan); |
| 821 | |
| 822 | /* Perform calibration if necessary */ |
Felix Fietkau | 35ecfe0 | 2010-09-29 17:15:26 +0200 | [diff] [blame] | 823 | if (longcal || shortcal) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 824 | common->ani.caldone = |
| 825 | ath9k_hw_calibrate(ah, ah->curchan, |
Felix Fietkau | 82b2d33 | 2011-09-03 01:40:23 +0200 | [diff] [blame] | 826 | ah->rxchainmask, longcal); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 827 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 828 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 829 | } |
| 830 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 831 | set_timer: |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 832 | /* |
| 833 | * Set timer interval based on previous results. |
| 834 | * The interval must be the shortest necessary to satisfy ANI, |
| 835 | * short calibration and long calibration. |
| 836 | */ |
| 837 | cal_interval = ATH_LONG_CALINTERVAL; |
Sujith Manoharan | e323300 | 2013-06-03 09:19:26 +0530 | [diff] [blame] | 838 | cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 839 | if (!common->ani.caldone) |
| 840 | cal_interval = min(cal_interval, (u32)short_cal_interval); |
| 841 | |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 842 | ieee80211_queue_delayed_work(common->hw, &priv->ani_work, |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 843 | msecs_to_jiffies(cal_interval)); |
| 844 | } |
| 845 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 846 | /**********************/ |
| 847 | /* mac80211 Callbacks */ |
| 848 | /**********************/ |
| 849 | |
Thomas Huehn | 36323f8 | 2012-07-23 21:33:42 +0200 | [diff] [blame] | 850 | static void ath9k_htc_tx(struct ieee80211_hw *hw, |
| 851 | struct ieee80211_tx_control *control, |
| 852 | struct sk_buff *skb) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 853 | { |
| 854 | struct ieee80211_hdr *hdr; |
| 855 | struct ath9k_htc_priv *priv = hw->priv; |
Sujith Manoharan | 8e86a54 | 2011-04-13 11:25:29 +0530 | [diff] [blame] | 856 | struct ath_common *common = ath9k_hw_common(priv->ah); |
Sujith Manoharan | 2c5d57f | 2011-04-13 11:25:47 +0530 | [diff] [blame] | 857 | int padpos, padsize, ret, slot; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 858 | |
| 859 | hdr = (struct ieee80211_hdr *) skb->data; |
| 860 | |
| 861 | /* Add the padding after the header if this is not already done */ |
Felix Fietkau | c60c992 | 2013-04-08 00:04:09 +0200 | [diff] [blame] | 862 | padpos = ieee80211_hdrlen(hdr->frame_control); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 863 | padsize = padpos & 3; |
| 864 | if (padsize && skb->len > padpos) { |
Sujith Manoharan | 8e86a54 | 2011-04-13 11:25:29 +0530 | [diff] [blame] | 865 | if (skb_headroom(skb) < padsize) { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 866 | ath_dbg(common, XMIT, "No room for padding\n"); |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 867 | goto fail_tx; |
Sujith Manoharan | 8e86a54 | 2011-04-13 11:25:29 +0530 | [diff] [blame] | 868 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 869 | skb_push(skb, padsize); |
| 870 | memmove(skb->data, skb->data + padsize, padpos); |
| 871 | } |
| 872 | |
Sujith Manoharan | 2c5d57f | 2011-04-13 11:25:47 +0530 | [diff] [blame] | 873 | slot = ath9k_htc_tx_get_slot(priv); |
| 874 | if (slot < 0) { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 875 | ath_dbg(common, XMIT, "No free TX slot\n"); |
Sujith Manoharan | 2c5d57f | 2011-04-13 11:25:47 +0530 | [diff] [blame] | 876 | goto fail_tx; |
| 877 | } |
| 878 | |
Thomas Huehn | 36323f8 | 2012-07-23 21:33:42 +0200 | [diff] [blame] | 879 | ret = ath9k_htc_tx_start(priv, control->sta, skb, slot, false); |
Sujith | 7757dfe | 2010-03-29 16:07:17 +0530 | [diff] [blame] | 880 | if (ret != 0) { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 881 | ath_dbg(common, XMIT, "Tx failed\n"); |
Sujith Manoharan | 2c5d57f | 2011-04-13 11:25:47 +0530 | [diff] [blame] | 882 | goto clear_slot; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 883 | } |
| 884 | |
Sujith Manoharan | 8e86a54 | 2011-04-13 11:25:29 +0530 | [diff] [blame] | 885 | ath9k_htc_check_stop_queues(priv); |
| 886 | |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 887 | return; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 888 | |
Sujith Manoharan | 2c5d57f | 2011-04-13 11:25:47 +0530 | [diff] [blame] | 889 | clear_slot: |
| 890 | ath9k_htc_tx_clear_slot(priv, slot); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 891 | fail_tx: |
| 892 | dev_kfree_skb_any(skb); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 893 | } |
| 894 | |
Sujith | 881ac6a | 2010-06-01 15:14:11 +0530 | [diff] [blame] | 895 | static int ath9k_htc_start(struct ieee80211_hw *hw) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 896 | { |
| 897 | struct ath9k_htc_priv *priv = hw->priv; |
| 898 | struct ath_hw *ah = priv->ah; |
| 899 | struct ath_common *common = ath9k_hw_common(ah); |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 900 | struct ieee80211_channel *curchan = hw->conf.chandef.chan; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 901 | struct ath9k_channel *init_channel; |
| 902 | int ret = 0; |
| 903 | enum htc_phymode mode; |
Sujith | 7f1f5a0 | 2010-04-16 11:54:03 +0530 | [diff] [blame] | 904 | __be16 htc_mode; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 905 | u8 cmd_rsp; |
| 906 | |
Sujith | 881ac6a | 2010-06-01 15:14:11 +0530 | [diff] [blame] | 907 | mutex_lock(&priv->mutex); |
| 908 | |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 909 | ath_dbg(common, CONFIG, |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 910 | "Starting driver with initial channel: %d MHz\n", |
| 911 | curchan->center_freq); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 912 | |
Sujith | 21d5130 | 2010-06-01 15:14:18 +0530 | [diff] [blame] | 913 | /* Ensure that HW is awake before flushing RX */ |
| 914 | ath9k_htc_setpower(priv, ATH9K_PM_AWAKE); |
| 915 | WMI_CMD(WMI_FLUSH_RECV_CMDID); |
| 916 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 917 | /* setup initial channel */ |
Felix Fietkau | 2297f1c | 2013-10-11 23:30:57 +0200 | [diff] [blame] | 918 | init_channel = ath9k_cmn_get_channel(hw, ah, &hw->conf.chandef); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 919 | |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 920 | ret = ath9k_hw_reset(ah, init_channel, ah->caldata, false); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 921 | if (ret) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 922 | ath_err(common, |
| 923 | "Unable to reset hardware; reset status %d (freq %u MHz)\n", |
| 924 | ret, curchan->center_freq); |
Sujith | 881ac6a | 2010-06-01 15:14:11 +0530 | [diff] [blame] | 925 | mutex_unlock(&priv->mutex); |
Vivek Natarajan | 8a8572a | 2010-04-27 13:05:37 +0530 | [diff] [blame] | 926 | return ret; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 927 | } |
| 928 | |
Rajkumar Manoharan | b2a5c3d | 2011-01-31 23:47:45 +0530 | [diff] [blame] | 929 | ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit, |
| 930 | &priv->curtxpow); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 931 | |
| 932 | mode = ath9k_htc_get_curmode(priv, init_channel); |
| 933 | htc_mode = cpu_to_be16(mode); |
| 934 | WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 935 | WMI_CMD(WMI_ATH_INIT_CMDID); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 936 | WMI_CMD(WMI_START_RECV_CMDID); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 937 | |
| 938 | ath9k_host_rx_init(priv); |
| 939 | |
Sujith Manoharan | 3a0593e | 2011-04-20 14:33:28 +0530 | [diff] [blame] | 940 | ret = ath9k_htc_update_cap_target(priv, 0); |
Sujith Manoharan | 1057b75 | 2011-02-21 07:48:09 +0530 | [diff] [blame] | 941 | if (ret) |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 942 | ath_dbg(common, CONFIG, |
Sujith Manoharan | 1057b75 | 2011-02-21 07:48:09 +0530 | [diff] [blame] | 943 | "Failed to update capability in target\n"); |
| 944 | |
Sujith Manoharan | d8a2c51 | 2012-06-25 13:54:41 +0530 | [diff] [blame] | 945 | clear_bit(OP_INVALID, &priv->op_flags); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 946 | htc_start(priv->htc); |
| 947 | |
Sujith Manoharan | 658ef04 | 2011-04-13 11:25:00 +0530 | [diff] [blame] | 948 | spin_lock_bh(&priv->tx.tx_lock); |
Sujith Manoharan | 8e86a54 | 2011-04-13 11:25:29 +0530 | [diff] [blame] | 949 | priv->tx.flags &= ~ATH9K_HTC_OP_TX_QUEUES_STOP; |
Sujith Manoharan | 658ef04 | 2011-04-13 11:25:00 +0530 | [diff] [blame] | 950 | spin_unlock_bh(&priv->tx.tx_lock); |
Sujith | 7757dfe | 2010-03-29 16:07:17 +0530 | [diff] [blame] | 951 | |
| 952 | ieee80211_wake_queues(hw); |
| 953 | |
Sujith Manoharan | 859c3ca | 2011-04-13 11:26:39 +0530 | [diff] [blame] | 954 | mod_timer(&priv->tx.cleanup_timer, |
| 955 | jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL)); |
| 956 | |
Sujith Manoharan | bf047fc | 2012-02-22 12:41:36 +0530 | [diff] [blame] | 957 | ath9k_htc_start_btcoex(priv); |
| 958 | |
Vivek Natarajan | 8a8572a | 2010-04-27 13:05:37 +0530 | [diff] [blame] | 959 | mutex_unlock(&priv->mutex); |
| 960 | |
| 961 | return ret; |
| 962 | } |
| 963 | |
Sujith | 881ac6a | 2010-06-01 15:14:11 +0530 | [diff] [blame] | 964 | static void ath9k_htc_stop(struct ieee80211_hw *hw) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 965 | { |
| 966 | struct ath9k_htc_priv *priv = hw->priv; |
| 967 | struct ath_hw *ah = priv->ah; |
| 968 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith Manoharan | 0ff2b5c | 2011-04-20 11:00:34 +0530 | [diff] [blame] | 969 | int ret __attribute__ ((unused)); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 970 | u8 cmd_rsp; |
| 971 | |
Sujith | 881ac6a | 2010-06-01 15:14:11 +0530 | [diff] [blame] | 972 | mutex_lock(&priv->mutex); |
| 973 | |
Sujith Manoharan | d8a2c51 | 2012-06-25 13:54:41 +0530 | [diff] [blame] | 974 | if (test_bit(OP_INVALID, &priv->op_flags)) { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 975 | ath_dbg(common, ANY, "Device not present\n"); |
Sujith | 881ac6a | 2010-06-01 15:14:11 +0530 | [diff] [blame] | 976 | mutex_unlock(&priv->mutex); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 977 | return; |
| 978 | } |
| 979 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 980 | ath9k_htc_ps_wakeup(priv); |
Sujith Manoharan | b587fc8 | 2011-04-13 11:25:59 +0530 | [diff] [blame] | 981 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 982 | WMI_CMD(WMI_DISABLE_INTR_CMDID); |
| 983 | WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID); |
| 984 | WMI_CMD(WMI_STOP_RECV_CMDID); |
Stanislaw Gruszka | ea88835 | 2011-01-25 14:15:12 +0100 | [diff] [blame] | 985 | |
Stanislaw Gruszka | ea88835 | 2011-01-25 14:15:12 +0100 | [diff] [blame] | 986 | tasklet_kill(&priv->rx_tasklet); |
Stanislaw Gruszka | ea88835 | 2011-01-25 14:15:12 +0100 | [diff] [blame] | 987 | |
Sujith Manoharan | 859c3ca | 2011-04-13 11:26:39 +0530 | [diff] [blame] | 988 | del_timer_sync(&priv->tx.cleanup_timer); |
Sujith Manoharan | b587fc8 | 2011-04-13 11:25:59 +0530 | [diff] [blame] | 989 | ath9k_htc_tx_drain(priv); |
Sujith Manoharan | f4c8899 | 2011-04-13 11:23:52 +0530 | [diff] [blame] | 990 | ath9k_wmi_event_drain(priv); |
| 991 | |
Stanislaw Gruszka | ea88835 | 2011-01-25 14:15:12 +0100 | [diff] [blame] | 992 | mutex_unlock(&priv->mutex); |
| 993 | |
| 994 | /* Cancel all the running timers/work .. */ |
| 995 | cancel_work_sync(&priv->fatal_work); |
| 996 | cancel_work_sync(&priv->ps_work); |
Sujith Manoharan | d244f21 | 2011-04-28 16:14:05 +0530 | [diff] [blame] | 997 | |
| 998 | #ifdef CONFIG_MAC80211_LEDS |
| 999 | cancel_work_sync(&priv->led_work); |
| 1000 | #endif |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 1001 | ath9k_htc_stop_ani(priv); |
Stanislaw Gruszka | ea88835 | 2011-01-25 14:15:12 +0100 | [diff] [blame] | 1002 | |
| 1003 | mutex_lock(&priv->mutex); |
| 1004 | |
Sujith Manoharan | bf047fc | 2012-02-22 12:41:36 +0530 | [diff] [blame] | 1005 | ath9k_htc_stop_btcoex(priv); |
Vivek Natarajan | 21cb987 | 2010-08-18 19:57:49 +0530 | [diff] [blame] | 1006 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 1007 | /* Remove a monitor interface if it's present. */ |
| 1008 | if (priv->ah->is_monitoring) |
| 1009 | ath9k_htc_remove_monitor_interface(priv); |
| 1010 | |
Sujith | e9201f0 | 2010-06-01 15:14:17 +0530 | [diff] [blame] | 1011 | ath9k_hw_phy_disable(ah); |
| 1012 | ath9k_hw_disable(ah); |
Sujith | e9201f0 | 2010-06-01 15:14:17 +0530 | [diff] [blame] | 1013 | ath9k_htc_ps_restore(priv); |
| 1014 | ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP); |
| 1015 | |
Sujith Manoharan | d8a2c51 | 2012-06-25 13:54:41 +0530 | [diff] [blame] | 1016 | set_bit(OP_INVALID, &priv->op_flags); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1017 | |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 1018 | ath_dbg(common, CONFIG, "Driver halt\n"); |
Vivek Natarajan | 8a8572a | 2010-04-27 13:05:37 +0530 | [diff] [blame] | 1019 | mutex_unlock(&priv->mutex); |
| 1020 | } |
| 1021 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1022 | static int ath9k_htc_add_interface(struct ieee80211_hw *hw, |
| 1023 | struct ieee80211_vif *vif) |
| 1024 | { |
| 1025 | struct ath9k_htc_priv *priv = hw->priv; |
| 1026 | struct ath9k_htc_vif *avp = (void *)vif->drv_priv; |
| 1027 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 1028 | struct ath9k_htc_target_vif hvif; |
| 1029 | int ret = 0; |
| 1030 | u8 cmd_rsp; |
| 1031 | |
| 1032 | mutex_lock(&priv->mutex); |
| 1033 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1034 | ath9k_htc_ps_wakeup(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1035 | memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif)); |
| 1036 | memcpy(&hvif.myaddr, vif->addr, ETH_ALEN); |
| 1037 | |
| 1038 | switch (vif->type) { |
| 1039 | case NL80211_IFTYPE_STATION: |
Sujith Manoharan | e4c6250 | 2011-04-13 11:24:43 +0530 | [diff] [blame] | 1040 | hvif.opmode = HTC_M_STA; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1041 | break; |
| 1042 | case NL80211_IFTYPE_ADHOC: |
Sujith Manoharan | e4c6250 | 2011-04-13 11:24:43 +0530 | [diff] [blame] | 1043 | hvif.opmode = HTC_M_IBSS; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1044 | break; |
Sujith Manoharan | da8d9d9 | 2011-02-21 07:49:23 +0530 | [diff] [blame] | 1045 | case NL80211_IFTYPE_AP: |
Sujith Manoharan | e4c6250 | 2011-04-13 11:24:43 +0530 | [diff] [blame] | 1046 | hvif.opmode = HTC_M_HOSTAP; |
Sujith Manoharan | da8d9d9 | 2011-02-21 07:49:23 +0530 | [diff] [blame] | 1047 | break; |
Javier Cardona | 594e65b | 2013-05-08 10:16:46 -0700 | [diff] [blame] | 1048 | case NL80211_IFTYPE_MESH_POINT: |
| 1049 | hvif.opmode = HTC_M_WDS; /* close enough */ |
| 1050 | break; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1051 | default: |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 1052 | ath_err(common, |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1053 | "Interface type %d not yet supported\n", vif->type); |
| 1054 | ret = -EOPNOTSUPP; |
| 1055 | goto out; |
| 1056 | } |
| 1057 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1058 | /* Index starts from zero on the target */ |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 1059 | avp->index = hvif.index = ffz(priv->vif_slot); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1060 | hvif.rtsthreshold = cpu_to_be16(2304); |
| 1061 | WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif); |
| 1062 | if (ret) |
| 1063 | goto out; |
| 1064 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1065 | /* |
| 1066 | * We need a node in target to tx mgmt frames |
| 1067 | * before association. |
| 1068 | */ |
| 1069 | ret = ath9k_htc_add_station(priv, vif, NULL); |
Sujith Manoharan | ab77c70 | 2011-02-21 07:48:16 +0530 | [diff] [blame] | 1070 | if (ret) { |
| 1071 | WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1072 | goto out; |
Sujith Manoharan | ab77c70 | 2011-02-21 07:48:16 +0530 | [diff] [blame] | 1073 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1074 | |
Mathy Vanhoef | 657eb17 | 2013-11-28 12:21:45 +0100 | [diff] [blame] | 1075 | ath9k_htc_set_mac_bssid_mask(priv, vif); |
Sujith Manoharan | 585895c | 2011-02-21 07:48:46 +0530 | [diff] [blame] | 1076 | |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 1077 | priv->vif_slot |= (1 << avp->index); |
Sujith Manoharan | ab77c70 | 2011-02-21 07:48:16 +0530 | [diff] [blame] | 1078 | priv->nvifs++; |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 1079 | |
Sujith Manoharan | 0df8359 | 2011-02-21 07:49:15 +0530 | [diff] [blame] | 1080 | INC_VIF(priv, vif->type); |
Sujith Manoharan | 832f6a1 | 2011-04-13 11:23:08 +0530 | [diff] [blame] | 1081 | |
| 1082 | if ((vif->type == NL80211_IFTYPE_AP) || |
Javier Cardona | 594e65b | 2013-05-08 10:16:46 -0700 | [diff] [blame] | 1083 | (vif->type == NL80211_IFTYPE_MESH_POINT) || |
Sujith Manoharan | 832f6a1 | 2011-04-13 11:23:08 +0530 | [diff] [blame] | 1084 | (vif->type == NL80211_IFTYPE_ADHOC)) |
| 1085 | ath9k_htc_assign_bslot(priv, vif); |
| 1086 | |
Sujith Manoharan | ffbe7c8 | 2011-02-21 07:49:31 +0530 | [diff] [blame] | 1087 | ath9k_htc_set_opmode(priv); |
Sujith Manoharan | 0df8359 | 2011-02-21 07:49:15 +0530 | [diff] [blame] | 1088 | |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 1089 | if ((priv->ah->opmode == NL80211_IFTYPE_AP) && |
Sujith Manoharan | d8a2c51 | 2012-06-25 13:54:41 +0530 | [diff] [blame] | 1090 | !test_bit(OP_ANI_RUNNING, &priv->op_flags)) { |
Sujith Manoharan | 60ca9f8 | 2012-07-17 17:15:37 +0530 | [diff] [blame] | 1091 | ath9k_hw_set_tsfadjust(priv->ah, true); |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 1092 | ath9k_htc_start_ani(priv); |
Sujith Manoharan | 9b674a0 | 2011-04-13 11:23:17 +0530 | [diff] [blame] | 1093 | } |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 1094 | |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 1095 | ath_dbg(common, CONFIG, "Attach a VIF of type: %d at idx: %d\n", |
| 1096 | vif->type, avp->index); |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 1097 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1098 | out: |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1099 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1100 | mutex_unlock(&priv->mutex); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1101 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1102 | return ret; |
| 1103 | } |
| 1104 | |
| 1105 | static void ath9k_htc_remove_interface(struct ieee80211_hw *hw, |
| 1106 | struct ieee80211_vif *vif) |
| 1107 | { |
| 1108 | struct ath9k_htc_priv *priv = hw->priv; |
| 1109 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 1110 | struct ath9k_htc_vif *avp = (void *)vif->drv_priv; |
| 1111 | struct ath9k_htc_target_vif hvif; |
| 1112 | int ret = 0; |
| 1113 | u8 cmd_rsp; |
| 1114 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1115 | mutex_lock(&priv->mutex); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1116 | ath9k_htc_ps_wakeup(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1117 | |
| 1118 | memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif)); |
| 1119 | memcpy(&hvif.myaddr, vif->addr, ETH_ALEN); |
| 1120 | hvif.index = avp->index; |
| 1121 | WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif); |
Sujith Manoharan | 0ff2b5c | 2011-04-20 11:00:34 +0530 | [diff] [blame] | 1122 | if (ret) { |
| 1123 | ath_err(common, "Unable to remove interface at idx: %d\n", |
| 1124 | avp->index); |
| 1125 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1126 | priv->nvifs--; |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 1127 | priv->vif_slot &= ~(1 << avp->index); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1128 | |
| 1129 | ath9k_htc_remove_station(priv, vif, NULL); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1130 | |
Sujith Manoharan | 0df8359 | 2011-02-21 07:49:15 +0530 | [diff] [blame] | 1131 | DEC_VIF(priv, vif->type); |
Sujith Manoharan | 832f6a1 | 2011-04-13 11:23:08 +0530 | [diff] [blame] | 1132 | |
| 1133 | if ((vif->type == NL80211_IFTYPE_AP) || |
Javier Cardona | 594e65b | 2013-05-08 10:16:46 -0700 | [diff] [blame] | 1134 | vif->type == NL80211_IFTYPE_MESH_POINT || |
Sujith Manoharan | 832f6a1 | 2011-04-13 11:23:08 +0530 | [diff] [blame] | 1135 | (vif->type == NL80211_IFTYPE_ADHOC)) |
| 1136 | ath9k_htc_remove_bslot(priv, vif); |
| 1137 | |
Sujith Manoharan | ffbe7c8 | 2011-02-21 07:49:31 +0530 | [diff] [blame] | 1138 | ath9k_htc_set_opmode(priv); |
Sujith Manoharan | 0df8359 | 2011-02-21 07:49:15 +0530 | [diff] [blame] | 1139 | |
Mathy Vanhoef | 657eb17 | 2013-11-28 12:21:45 +0100 | [diff] [blame] | 1140 | ath9k_htc_set_mac_bssid_mask(priv, vif); |
Sujith Manoharan | db32124 | 2011-05-17 12:41:41 +0530 | [diff] [blame] | 1141 | |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 1142 | /* |
| 1143 | * Stop ANI only if there are no associated station interfaces. |
| 1144 | */ |
| 1145 | if ((vif->type == NL80211_IFTYPE_AP) && (priv->num_ap_vif == 0)) { |
| 1146 | priv->rearm_ani = false; |
Johannes Berg | 8b2c982 | 2012-11-06 20:23:30 +0100 | [diff] [blame] | 1147 | ieee80211_iterate_active_interfaces_atomic( |
| 1148 | priv->hw, IEEE80211_IFACE_ITER_RESUME_ALL, |
| 1149 | ath9k_htc_vif_iter, priv); |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 1150 | if (!priv->rearm_ani) |
| 1151 | ath9k_htc_stop_ani(priv); |
| 1152 | } |
| 1153 | |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 1154 | ath_dbg(common, CONFIG, "Detach Interface at idx: %d\n", avp->index); |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 1155 | |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1156 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1157 | mutex_unlock(&priv->mutex); |
| 1158 | } |
| 1159 | |
| 1160 | static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed) |
| 1161 | { |
| 1162 | struct ath9k_htc_priv *priv = hw->priv; |
| 1163 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 1164 | struct ieee80211_conf *conf = &hw->conf; |
Sujith Manoharan | 6bcfe67 | 2012-06-25 13:54:49 +0530 | [diff] [blame] | 1165 | bool chip_reset = false; |
| 1166 | int ret = 0; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1167 | |
| 1168 | mutex_lock(&priv->mutex); |
Sujith Manoharan | 6bcfe67 | 2012-06-25 13:54:49 +0530 | [diff] [blame] | 1169 | ath9k_htc_ps_wakeup(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1170 | |
Vivek Natarajan | 8a8572a | 2010-04-27 13:05:37 +0530 | [diff] [blame] | 1171 | if (changed & IEEE80211_CONF_CHANGE_IDLE) { |
Sujith | 2336776 | 2010-06-01 15:14:16 +0530 | [diff] [blame] | 1172 | mutex_lock(&priv->htc_pm_lock); |
Vivek Natarajan | 8a8572a | 2010-04-27 13:05:37 +0530 | [diff] [blame] | 1173 | |
Sujith Manoharan | 6bcfe67 | 2012-06-25 13:54:49 +0530 | [diff] [blame] | 1174 | priv->ps_idle = !!(conf->flags & IEEE80211_CONF_IDLE); |
Sujith Manoharan | 075163b | 2013-06-20 13:57:07 +0530 | [diff] [blame] | 1175 | if (!priv->ps_idle) |
Sujith Manoharan | 6bcfe67 | 2012-06-25 13:54:49 +0530 | [diff] [blame] | 1176 | chip_reset = true; |
| 1177 | |
| 1178 | mutex_unlock(&priv->htc_pm_lock); |
Vivek Natarajan | 8a8572a | 2010-04-27 13:05:37 +0530 | [diff] [blame] | 1179 | } |
| 1180 | |
Sujith Manoharan | 55de80d | 2011-01-05 01:06:21 +0530 | [diff] [blame] | 1181 | /* |
| 1182 | * Monitor interface should be added before |
| 1183 | * IEEE80211_CONF_CHANGE_CHANNEL is handled. |
| 1184 | */ |
| 1185 | if (changed & IEEE80211_CONF_CHANGE_MONITOR) { |
Sujith Manoharan | a97b478 | 2011-02-21 07:48:00 +0530 | [diff] [blame] | 1186 | if ((conf->flags & IEEE80211_CONF_MONITOR) && |
| 1187 | !priv->ah->is_monitoring) |
| 1188 | ath9k_htc_add_monitor_interface(priv); |
| 1189 | else if (priv->ah->is_monitoring) |
| 1190 | ath9k_htc_remove_monitor_interface(priv); |
Sujith Manoharan | 55de80d | 2011-01-05 01:06:21 +0530 | [diff] [blame] | 1191 | } |
| 1192 | |
Sujith Manoharan | 6bcfe67 | 2012-06-25 13:54:49 +0530 | [diff] [blame] | 1193 | if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) || chip_reset) { |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 1194 | struct ieee80211_channel *curchan = hw->conf.chandef.chan; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1195 | int pos = curchan->hw_value; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1196 | |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 1197 | ath_dbg(common, CONFIG, "Set channel: %d MHz\n", |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 1198 | curchan->center_freq); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1199 | |
Felix Fietkau | 2297f1c | 2013-10-11 23:30:57 +0200 | [diff] [blame] | 1200 | ath9k_cmn_get_channel(hw, priv->ah, &hw->conf.chandef); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1201 | if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 1202 | ath_err(common, "Unable to set channel\n"); |
Sujith Manoharan | 6bcfe67 | 2012-06-25 13:54:49 +0530 | [diff] [blame] | 1203 | ret = -EINVAL; |
| 1204 | goto out; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1205 | } |
| 1206 | |
| 1207 | } |
Sujith Manoharan | 692d6b1 | 2010-12-07 16:31:54 +0530 | [diff] [blame] | 1208 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1209 | if (changed & IEEE80211_CONF_CHANGE_PS) { |
| 1210 | if (conf->flags & IEEE80211_CONF_PS) { |
| 1211 | ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP); |
| 1212 | priv->ps_enabled = true; |
| 1213 | } else { |
| 1214 | priv->ps_enabled = false; |
| 1215 | cancel_work_sync(&priv->ps_work); |
| 1216 | ath9k_htc_setpower(priv, ATH9K_PM_AWAKE); |
| 1217 | } |
| 1218 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1219 | |
Sujith Manoharan | 692d6b1 | 2010-12-07 16:31:54 +0530 | [diff] [blame] | 1220 | if (changed & IEEE80211_CONF_CHANGE_POWER) { |
| 1221 | priv->txpowlimit = 2 * conf->power_level; |
Rajkumar Manoharan | b2a5c3d | 2011-01-31 23:47:45 +0530 | [diff] [blame] | 1222 | ath9k_cmn_update_txpow(priv->ah, priv->curtxpow, |
| 1223 | priv->txpowlimit, &priv->curtxpow); |
Sujith Manoharan | 692d6b1 | 2010-12-07 16:31:54 +0530 | [diff] [blame] | 1224 | } |
| 1225 | |
Sujith | 2336776 | 2010-06-01 15:14:16 +0530 | [diff] [blame] | 1226 | out: |
Sujith Manoharan | 6bcfe67 | 2012-06-25 13:54:49 +0530 | [diff] [blame] | 1227 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1228 | mutex_unlock(&priv->mutex); |
Sujith Manoharan | 6bcfe67 | 2012-06-25 13:54:49 +0530 | [diff] [blame] | 1229 | return ret; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1230 | } |
| 1231 | |
| 1232 | #define SUPPORTED_FILTERS \ |
| 1233 | (FIF_PROMISC_IN_BSS | \ |
| 1234 | FIF_ALLMULTI | \ |
| 1235 | FIF_CONTROL | \ |
| 1236 | FIF_PSPOLL | \ |
| 1237 | FIF_OTHER_BSS | \ |
| 1238 | FIF_BCN_PRBRESP_PROMISC | \ |
Rajkumar Manoharan | 94a40c0 | 2010-10-14 10:50:26 +0530 | [diff] [blame] | 1239 | FIF_PROBE_REQ | \ |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1240 | FIF_FCSFAIL) |
| 1241 | |
| 1242 | static void ath9k_htc_configure_filter(struct ieee80211_hw *hw, |
| 1243 | unsigned int changed_flags, |
| 1244 | unsigned int *total_flags, |
| 1245 | u64 multicast) |
| 1246 | { |
| 1247 | struct ath9k_htc_priv *priv = hw->priv; |
| 1248 | u32 rfilt; |
| 1249 | |
| 1250 | mutex_lock(&priv->mutex); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1251 | changed_flags &= SUPPORTED_FILTERS; |
| 1252 | *total_flags &= SUPPORTED_FILTERS; |
| 1253 | |
Sujith Manoharan | d8a2c51 | 2012-06-25 13:54:41 +0530 | [diff] [blame] | 1254 | if (test_bit(OP_INVALID, &priv->op_flags)) { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 1255 | ath_dbg(ath9k_hw_common(priv->ah), ANY, |
Rajkumar Manoharan | 565dfef | 2011-07-07 23:33:38 +0530 | [diff] [blame] | 1256 | "Unable to configure filter on invalid state\n"); |
Larry Finger | 1ba45b9 | 2011-08-27 13:56:00 -0500 | [diff] [blame] | 1257 | mutex_unlock(&priv->mutex); |
Rajkumar Manoharan | 565dfef | 2011-07-07 23:33:38 +0530 | [diff] [blame] | 1258 | return; |
| 1259 | } |
| 1260 | ath9k_htc_ps_wakeup(priv); |
| 1261 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1262 | priv->rxfilter = *total_flags; |
Sujith | 0995d11 | 2010-03-29 16:07:09 +0530 | [diff] [blame] | 1263 | rfilt = ath9k_htc_calcrxfilter(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1264 | ath9k_hw_setrxfilter(priv->ah, rfilt); |
| 1265 | |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 1266 | ath_dbg(ath9k_hw_common(priv->ah), CONFIG, "Set HW RX filter: 0x%x\n", |
| 1267 | rfilt); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1268 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1269 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1270 | mutex_unlock(&priv->mutex); |
| 1271 | } |
| 1272 | |
Sujith | abd984e | 2010-05-18 15:26:04 +0530 | [diff] [blame] | 1273 | static int ath9k_htc_sta_add(struct ieee80211_hw *hw, |
| 1274 | struct ieee80211_vif *vif, |
| 1275 | struct ieee80211_sta *sta) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1276 | { |
| 1277 | struct ath9k_htc_priv *priv = hw->priv; |
| 1278 | int ret; |
| 1279 | |
Sujith.Manoharan@atheros.com | 05a30f9 | 2010-05-11 16:24:38 +0530 | [diff] [blame] | 1280 | mutex_lock(&priv->mutex); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1281 | ath9k_htc_ps_wakeup(priv); |
Sujith | abd984e | 2010-05-18 15:26:04 +0530 | [diff] [blame] | 1282 | ret = ath9k_htc_add_station(priv, vif, sta); |
| 1283 | if (!ret) |
| 1284 | ath9k_htc_init_rate(priv, sta); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1285 | ath9k_htc_ps_restore(priv); |
Sujith.Manoharan@atheros.com | 05a30f9 | 2010-05-11 16:24:38 +0530 | [diff] [blame] | 1286 | mutex_unlock(&priv->mutex); |
Sujith | abd984e | 2010-05-18 15:26:04 +0530 | [diff] [blame] | 1287 | |
| 1288 | return ret; |
| 1289 | } |
| 1290 | |
| 1291 | static int ath9k_htc_sta_remove(struct ieee80211_hw *hw, |
| 1292 | struct ieee80211_vif *vif, |
| 1293 | struct ieee80211_sta *sta) |
| 1294 | { |
| 1295 | struct ath9k_htc_priv *priv = hw->priv; |
Sujith Manoharan | 84c9e164 | 2011-04-13 11:26:11 +0530 | [diff] [blame] | 1296 | struct ath9k_htc_sta *ista; |
Sujith | abd984e | 2010-05-18 15:26:04 +0530 | [diff] [blame] | 1297 | int ret; |
| 1298 | |
| 1299 | mutex_lock(&priv->mutex); |
| 1300 | ath9k_htc_ps_wakeup(priv); |
Sujith Manoharan | 84c9e164 | 2011-04-13 11:26:11 +0530 | [diff] [blame] | 1301 | ista = (struct ath9k_htc_sta *) sta->drv_priv; |
| 1302 | htc_sta_drain(priv->htc, ista->index); |
Sujith | abd984e | 2010-05-18 15:26:04 +0530 | [diff] [blame] | 1303 | ret = ath9k_htc_remove_station(priv, vif, sta); |
| 1304 | ath9k_htc_ps_restore(priv); |
| 1305 | mutex_unlock(&priv->mutex); |
| 1306 | |
| 1307 | return ret; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1308 | } |
| 1309 | |
Antonio Quartulli | 6957802 | 2012-08-12 19:36:41 +0200 | [diff] [blame] | 1310 | static void ath9k_htc_sta_rc_update(struct ieee80211_hw *hw, |
| 1311 | struct ieee80211_vif *vif, |
| 1312 | struct ieee80211_sta *sta, u32 changed) |
| 1313 | { |
| 1314 | struct ath9k_htc_priv *priv = hw->priv; |
| 1315 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 1316 | struct ath9k_htc_target_rate trate; |
| 1317 | |
| 1318 | mutex_lock(&priv->mutex); |
| 1319 | ath9k_htc_ps_wakeup(priv); |
| 1320 | |
| 1321 | if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) { |
| 1322 | memset(&trate, 0, sizeof(struct ath9k_htc_target_rate)); |
| 1323 | ath9k_htc_setup_rate(priv, sta, &trate); |
| 1324 | if (!ath9k_htc_send_rate_cmd(priv, &trate)) |
| 1325 | ath_dbg(common, CONFIG, |
| 1326 | "Supported rates for sta: %pM updated, rate caps: 0x%X\n", |
| 1327 | sta->addr, be32_to_cpu(trate.capflags)); |
| 1328 | else |
| 1329 | ath_dbg(common, CONFIG, |
| 1330 | "Unable to update supported rates for sta: %pM\n", |
| 1331 | sta->addr); |
| 1332 | } |
| 1333 | |
| 1334 | ath9k_htc_ps_restore(priv); |
| 1335 | mutex_unlock(&priv->mutex); |
| 1336 | } |
| 1337 | |
Eliad Peller | 8a3a3c8 | 2011-10-02 10:15:52 +0200 | [diff] [blame] | 1338 | static int ath9k_htc_conf_tx(struct ieee80211_hw *hw, |
| 1339 | struct ieee80211_vif *vif, u16 queue, |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1340 | const struct ieee80211_tx_queue_params *params) |
| 1341 | { |
| 1342 | struct ath9k_htc_priv *priv = hw->priv; |
| 1343 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 1344 | struct ath9k_tx_queue_info qi; |
| 1345 | int ret = 0, qnum; |
| 1346 | |
Sujith Manoharan | bea843c | 2012-11-21 18:13:10 +0530 | [diff] [blame] | 1347 | if (queue >= IEEE80211_NUM_ACS) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1348 | return 0; |
| 1349 | |
| 1350 | mutex_lock(&priv->mutex); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1351 | ath9k_htc_ps_wakeup(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1352 | |
| 1353 | memset(&qi, 0, sizeof(struct ath9k_tx_queue_info)); |
| 1354 | |
| 1355 | qi.tqi_aifs = params->aifs; |
| 1356 | qi.tqi_cwmin = params->cw_min; |
| 1357 | qi.tqi_cwmax = params->cw_max; |
Felix Fietkau | 531bd07 | 2012-07-15 19:53:34 +0200 | [diff] [blame] | 1358 | qi.tqi_burstTime = params->txop * 32; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1359 | |
| 1360 | qnum = get_hw_qnum(queue, priv->hwq_map); |
| 1361 | |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 1362 | ath_dbg(common, CONFIG, |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 1363 | "Configure tx [queue/hwq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n", |
| 1364 | queue, qnum, params->aifs, params->cw_min, |
| 1365 | params->cw_max, params->txop); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1366 | |
Sujith | e1572c5 | 2010-03-24 13:42:13 +0530 | [diff] [blame] | 1367 | ret = ath_htc_txq_update(priv, qnum, &qi); |
Sujith | 764580f | 2010-06-01 15:14:19 +0530 | [diff] [blame] | 1368 | if (ret) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 1369 | ath_err(common, "TXQ Update failed\n"); |
Sujith | 764580f | 2010-06-01 15:14:19 +0530 | [diff] [blame] | 1370 | goto out; |
| 1371 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1372 | |
Sujith | 764580f | 2010-06-01 15:14:19 +0530 | [diff] [blame] | 1373 | if ((priv->ah->opmode == NL80211_IFTYPE_ADHOC) && |
Sujith Manoharan | bea843c | 2012-11-21 18:13:10 +0530 | [diff] [blame] | 1374 | (qnum == priv->hwq_map[IEEE80211_AC_BE])) |
Sujith | 764580f | 2010-06-01 15:14:19 +0530 | [diff] [blame] | 1375 | ath9k_htc_beaconq_config(priv); |
| 1376 | out: |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1377 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1378 | mutex_unlock(&priv->mutex); |
| 1379 | |
| 1380 | return ret; |
| 1381 | } |
| 1382 | |
| 1383 | static int ath9k_htc_set_key(struct ieee80211_hw *hw, |
| 1384 | enum set_key_cmd cmd, |
| 1385 | struct ieee80211_vif *vif, |
| 1386 | struct ieee80211_sta *sta, |
| 1387 | struct ieee80211_key_conf *key) |
| 1388 | { |
| 1389 | struct ath9k_htc_priv *priv = hw->priv; |
| 1390 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 1391 | int ret = 0; |
| 1392 | |
Sujith | e1572c5 | 2010-03-24 13:42:13 +0530 | [diff] [blame] | 1393 | if (htc_modparam_nohwcrypt) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1394 | return -ENOSPC; |
| 1395 | |
Antonio Quartulli | d7d312c | 2012-01-17 23:13:30 +0100 | [diff] [blame] | 1396 | if ((vif->type == NL80211_IFTYPE_ADHOC || |
| 1397 | vif->type == NL80211_IFTYPE_MESH_POINT) && |
| 1398 | (key->cipher == WLAN_CIPHER_SUITE_TKIP || |
| 1399 | key->cipher == WLAN_CIPHER_SUITE_CCMP) && |
| 1400 | !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) { |
| 1401 | /* |
| 1402 | * For now, disable hw crypto for the RSN IBSS group keys. This |
| 1403 | * could be optimized in the future to use a modified key cache |
| 1404 | * design to support per-STA RX GTK, but until that gets |
| 1405 | * implemented, use of software crypto for group addressed |
| 1406 | * frames is a acceptable to allow RSN IBSS to be used. |
| 1407 | */ |
| 1408 | return -EOPNOTSUPP; |
| 1409 | } |
| 1410 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1411 | mutex_lock(&priv->mutex); |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 1412 | ath_dbg(common, CONFIG, "Set HW Key\n"); |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1413 | ath9k_htc_ps_wakeup(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1414 | |
| 1415 | switch (cmd) { |
| 1416 | case SET_KEY: |
Bruno Randolf | 040e539 | 2010-09-08 16:05:04 +0900 | [diff] [blame] | 1417 | ret = ath_key_config(common, vif, sta, key); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1418 | if (ret >= 0) { |
| 1419 | key->hw_key_idx = ret; |
| 1420 | /* push IV and Michael MIC generation to stack */ |
| 1421 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 1422 | if (key->cipher == WLAN_CIPHER_SUITE_TKIP) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1423 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 1424 | if (priv->ah->sw_mgmt_crypto && |
| 1425 | key->cipher == WLAN_CIPHER_SUITE_CCMP) |
Johannes Berg | e548c49 | 2012-09-04 17:08:23 +0200 | [diff] [blame] | 1426 | key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1427 | ret = 0; |
| 1428 | } |
| 1429 | break; |
| 1430 | case DISABLE_KEY: |
Bruno Randolf | 040e539 | 2010-09-08 16:05:04 +0900 | [diff] [blame] | 1431 | ath_key_delete(common, key); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1432 | break; |
| 1433 | default: |
| 1434 | ret = -EINVAL; |
| 1435 | } |
| 1436 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1437 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1438 | mutex_unlock(&priv->mutex); |
| 1439 | |
| 1440 | return ret; |
| 1441 | } |
| 1442 | |
Sujith Manoharan | 0cd075d | 2011-05-17 12:42:03 +0530 | [diff] [blame] | 1443 | static void ath9k_htc_set_bssid(struct ath9k_htc_priv *priv) |
| 1444 | { |
| 1445 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 1446 | |
| 1447 | ath9k_hw_write_associd(priv->ah); |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 1448 | ath_dbg(common, CONFIG, "BSSID: %pM aid: 0x%x\n", |
Sujith Manoharan | 0cd075d | 2011-05-17 12:42:03 +0530 | [diff] [blame] | 1449 | common->curbssid, common->curaid); |
| 1450 | } |
| 1451 | |
| 1452 | static void ath9k_htc_bss_iter(void *data, u8 *mac, struct ieee80211_vif *vif) |
| 1453 | { |
| 1454 | struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *)data; |
| 1455 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 1456 | struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; |
| 1457 | |
| 1458 | if ((vif->type == NL80211_IFTYPE_STATION) && bss_conf->assoc) { |
| 1459 | common->curaid = bss_conf->aid; |
| 1460 | memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN); |
| 1461 | } |
| 1462 | } |
| 1463 | |
| 1464 | static void ath9k_htc_choose_set_bssid(struct ath9k_htc_priv *priv) |
| 1465 | { |
| 1466 | if (priv->num_sta_assoc_vif == 1) { |
Johannes Berg | 8b2c982 | 2012-11-06 20:23:30 +0100 | [diff] [blame] | 1467 | ieee80211_iterate_active_interfaces_atomic( |
| 1468 | priv->hw, IEEE80211_IFACE_ITER_RESUME_ALL, |
| 1469 | ath9k_htc_bss_iter, priv); |
Sujith Manoharan | 0cd075d | 2011-05-17 12:42:03 +0530 | [diff] [blame] | 1470 | ath9k_htc_set_bssid(priv); |
| 1471 | } |
| 1472 | } |
| 1473 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1474 | static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw, |
| 1475 | struct ieee80211_vif *vif, |
| 1476 | struct ieee80211_bss_conf *bss_conf, |
| 1477 | u32 changed) |
| 1478 | { |
| 1479 | struct ath9k_htc_priv *priv = hw->priv; |
| 1480 | struct ath_hw *ah = priv->ah; |
| 1481 | struct ath_common *common = ath9k_hw_common(ah); |
| 1482 | |
| 1483 | mutex_lock(&priv->mutex); |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1484 | ath9k_htc_ps_wakeup(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1485 | |
Sujith Manoharan | e7a2a4f | 2011-02-27 09:20:40 +0530 | [diff] [blame] | 1486 | if (changed & BSS_CHANGED_ASSOC) { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 1487 | ath_dbg(common, CONFIG, "BSS Changed ASSOC %d\n", |
Sujith Manoharan | 0cd075d | 2011-05-17 12:42:03 +0530 | [diff] [blame] | 1488 | bss_conf->assoc); |
Sujith Manoharan | e7a2a4f | 2011-02-27 09:20:40 +0530 | [diff] [blame] | 1489 | |
Sujith Manoharan | 0cd075d | 2011-05-17 12:42:03 +0530 | [diff] [blame] | 1490 | bss_conf->assoc ? |
| 1491 | priv->num_sta_assoc_vif++ : priv->num_sta_assoc_vif--; |
Sujith Manoharan | e7a2a4f | 2011-02-27 09:20:40 +0530 | [diff] [blame] | 1492 | |
Sujith Manoharan | 0cd075d | 2011-05-17 12:42:03 +0530 | [diff] [blame] | 1493 | if (priv->ah->opmode == NL80211_IFTYPE_STATION) { |
Rajkumar Manoharan | 931cb03 | 2012-06-20 16:29:20 +0530 | [diff] [blame] | 1494 | ath9k_htc_choose_set_bssid(priv); |
Sujith Manoharan | 0cd075d | 2011-05-17 12:42:03 +0530 | [diff] [blame] | 1495 | if (bss_conf->assoc && (priv->num_sta_assoc_vif == 1)) |
Sujith Manoharan | e7a2a4f | 2011-02-27 09:20:40 +0530 | [diff] [blame] | 1496 | ath9k_htc_start_ani(priv); |
Sujith Manoharan | 0cd075d | 2011-05-17 12:42:03 +0530 | [diff] [blame] | 1497 | else if (priv->num_sta_assoc_vif == 0) |
Sujith Manoharan | e7a2a4f | 2011-02-27 09:20:40 +0530 | [diff] [blame] | 1498 | ath9k_htc_stop_ani(priv); |
| 1499 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1500 | } |
| 1501 | |
Rajkumar Manoharan | 931cb03 | 2012-06-20 16:29:20 +0530 | [diff] [blame] | 1502 | if (changed & BSS_CHANGED_IBSS) { |
Sujith Manoharan | 0cd075d | 2011-05-17 12:42:03 +0530 | [diff] [blame] | 1503 | if (priv->ah->opmode == NL80211_IFTYPE_ADHOC) { |
| 1504 | common->curaid = bss_conf->aid; |
Sujith Manoharan | e7a2a4f | 2011-02-27 09:20:40 +0530 | [diff] [blame] | 1505 | memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN); |
Sujith Manoharan | 0cd075d | 2011-05-17 12:42:03 +0530 | [diff] [blame] | 1506 | ath9k_htc_set_bssid(priv); |
Sujith Manoharan | e7a2a4f | 2011-02-27 09:20:40 +0530 | [diff] [blame] | 1507 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1508 | } |
| 1509 | |
Sujith Manoharan | a5fae37 | 2011-02-21 07:49:53 +0530 | [diff] [blame] | 1510 | if ((changed & BSS_CHANGED_BEACON_ENABLED) && bss_conf->enable_beacon) { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 1511 | ath_dbg(common, CONFIG, "Beacon enabled for BSS: %pM\n", |
| 1512 | bss_conf->bssid); |
Sujith Manoharan | 9b674a0 | 2011-04-13 11:23:17 +0530 | [diff] [blame] | 1513 | ath9k_htc_set_tsfadjust(priv, vif); |
Sujith Manoharan | d8a2c51 | 2012-06-25 13:54:41 +0530 | [diff] [blame] | 1514 | set_bit(OP_ENABLE_BEACON, &priv->op_flags); |
Vivek Natarajan | 1c3652a | 2010-04-05 14:48:06 +0530 | [diff] [blame] | 1515 | ath9k_htc_beacon_config(priv, vif); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1516 | } |
| 1517 | |
Sujith Manoharan | a5fae37 | 2011-02-21 07:49:53 +0530 | [diff] [blame] | 1518 | if ((changed & BSS_CHANGED_BEACON_ENABLED) && !bss_conf->enable_beacon) { |
| 1519 | /* |
| 1520 | * Disable SWBA interrupt only if there are no |
Javier Cardona | 594e65b | 2013-05-08 10:16:46 -0700 | [diff] [blame] | 1521 | * concurrent AP/mesh or IBSS interfaces. |
Sujith Manoharan | a5fae37 | 2011-02-21 07:49:53 +0530 | [diff] [blame] | 1522 | */ |
Javier Cardona | 594e65b | 2013-05-08 10:16:46 -0700 | [diff] [blame] | 1523 | if ((priv->num_ap_vif + priv->num_mbss_vif <= 1) || |
| 1524 | priv->num_ibss_vif) { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 1525 | ath_dbg(common, CONFIG, |
Sujith Manoharan | a5fae37 | 2011-02-21 07:49:53 +0530 | [diff] [blame] | 1526 | "Beacon disabled for BSS: %pM\n", |
| 1527 | bss_conf->bssid); |
Sujith Manoharan | d8a2c51 | 2012-06-25 13:54:41 +0530 | [diff] [blame] | 1528 | clear_bit(OP_ENABLE_BEACON, &priv->op_flags); |
Sujith Manoharan | a5fae37 | 2011-02-21 07:49:53 +0530 | [diff] [blame] | 1529 | ath9k_htc_beacon_config(priv, vif); |
| 1530 | } |
| 1531 | } |
| 1532 | |
| 1533 | if (changed & BSS_CHANGED_BEACON_INT) { |
| 1534 | /* |
Javier Cardona | 594e65b | 2013-05-08 10:16:46 -0700 | [diff] [blame] | 1535 | * Reset the HW TSF for the first AP or mesh interface. |
Sujith Manoharan | a5fae37 | 2011-02-21 07:49:53 +0530 | [diff] [blame] | 1536 | */ |
Javier Cardona | 594e65b | 2013-05-08 10:16:46 -0700 | [diff] [blame] | 1537 | if (priv->nvifs == 1 && |
| 1538 | ((priv->ah->opmode == NL80211_IFTYPE_AP && |
| 1539 | vif->type == NL80211_IFTYPE_AP && |
| 1540 | priv->num_ap_vif == 1) || |
| 1541 | (priv->ah->opmode == NL80211_IFTYPE_MESH_POINT && |
| 1542 | vif->type == NL80211_IFTYPE_MESH_POINT && |
| 1543 | priv->num_mbss_vif == 1))) { |
Sujith Manoharan | d8a2c51 | 2012-06-25 13:54:41 +0530 | [diff] [blame] | 1544 | set_bit(OP_TSF_RESET, &priv->op_flags); |
Sujith Manoharan | a5fae37 | 2011-02-21 07:49:53 +0530 | [diff] [blame] | 1545 | } |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 1546 | ath_dbg(common, CONFIG, |
Sujith Manoharan | a5fae37 | 2011-02-21 07:49:53 +0530 | [diff] [blame] | 1547 | "Beacon interval changed for BSS: %pM\n", |
| 1548 | bss_conf->bssid); |
Vivek Natarajan | 1c3652a | 2010-04-05 14:48:06 +0530 | [diff] [blame] | 1549 | ath9k_htc_beacon_config(priv, vif); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1550 | } |
| 1551 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1552 | if (changed & BSS_CHANGED_ERP_SLOT) { |
| 1553 | if (bss_conf->use_short_slot) |
| 1554 | ah->slottime = 9; |
| 1555 | else |
| 1556 | ah->slottime = 20; |
| 1557 | |
| 1558 | ath9k_hw_init_global_settings(ah); |
| 1559 | } |
| 1560 | |
Sujith | 2c76ef8 | 2010-05-17 12:01:18 +0530 | [diff] [blame] | 1561 | if (changed & BSS_CHANGED_HT) |
| 1562 | ath9k_htc_update_rate(priv, vif, bss_conf); |
| 1563 | |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1564 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1565 | mutex_unlock(&priv->mutex); |
| 1566 | } |
| 1567 | |
Eliad Peller | 37a41b4 | 2011-09-21 14:06:11 +0300 | [diff] [blame] | 1568 | static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw, |
| 1569 | struct ieee80211_vif *vif) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1570 | { |
| 1571 | struct ath9k_htc_priv *priv = hw->priv; |
| 1572 | u64 tsf; |
| 1573 | |
| 1574 | mutex_lock(&priv->mutex); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1575 | ath9k_htc_ps_wakeup(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1576 | tsf = ath9k_hw_gettsf64(priv->ah); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1577 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1578 | mutex_unlock(&priv->mutex); |
| 1579 | |
| 1580 | return tsf; |
| 1581 | } |
| 1582 | |
Eliad Peller | 37a41b4 | 2011-09-21 14:06:11 +0300 | [diff] [blame] | 1583 | static void ath9k_htc_set_tsf(struct ieee80211_hw *hw, |
| 1584 | struct ieee80211_vif *vif, u64 tsf) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1585 | { |
| 1586 | struct ath9k_htc_priv *priv = hw->priv; |
| 1587 | |
| 1588 | mutex_lock(&priv->mutex); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1589 | ath9k_htc_ps_wakeup(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1590 | ath9k_hw_settsf64(priv->ah, tsf); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1591 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1592 | mutex_unlock(&priv->mutex); |
| 1593 | } |
| 1594 | |
Eliad Peller | 37a41b4 | 2011-09-21 14:06:11 +0300 | [diff] [blame] | 1595 | static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw, |
| 1596 | struct ieee80211_vif *vif) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1597 | { |
| 1598 | struct ath9k_htc_priv *priv = hw->priv; |
| 1599 | |
| 1600 | mutex_lock(&priv->mutex); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1601 | ath9k_htc_ps_wakeup(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1602 | ath9k_hw_reset_tsf(priv->ah); |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1603 | ath9k_htc_ps_restore(priv); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1604 | mutex_unlock(&priv->mutex); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1605 | } |
| 1606 | |
| 1607 | static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw, |
| 1608 | struct ieee80211_vif *vif, |
| 1609 | enum ieee80211_ampdu_mlme_action action, |
| 1610 | struct ieee80211_sta *sta, |
Johannes Berg | 0b01f03 | 2011-01-18 13:51:05 +0100 | [diff] [blame] | 1611 | u16 tid, u16 *ssn, u8 buf_size) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1612 | { |
| 1613 | struct ath9k_htc_priv *priv = hw->priv; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1614 | struct ath9k_htc_sta *ista; |
Sujith | d7ca213 | 2010-06-15 10:24:37 +0530 | [diff] [blame] | 1615 | int ret = 0; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1616 | |
Sujith Manoharan | 87df895 | 2011-02-21 07:49:08 +0530 | [diff] [blame] | 1617 | mutex_lock(&priv->mutex); |
Sujith Manoharan | c58ca5b | 2011-04-20 11:01:10 +0530 | [diff] [blame] | 1618 | ath9k_htc_ps_wakeup(priv); |
Sujith Manoharan | 87df895 | 2011-02-21 07:49:08 +0530 | [diff] [blame] | 1619 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1620 | switch (action) { |
| 1621 | case IEEE80211_AMPDU_RX_START: |
| 1622 | break; |
| 1623 | case IEEE80211_AMPDU_RX_STOP: |
| 1624 | break; |
| 1625 | case IEEE80211_AMPDU_TX_START: |
Sujith | d7ca213 | 2010-06-15 10:24:37 +0530 | [diff] [blame] | 1626 | ret = ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid); |
| 1627 | if (!ret) |
| 1628 | ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 1629 | break; |
Johannes Berg | 18b559d | 2012-07-18 13:51:25 +0200 | [diff] [blame] | 1630 | case IEEE80211_AMPDU_TX_STOP_CONT: |
| 1631 | case IEEE80211_AMPDU_TX_STOP_FLUSH: |
| 1632 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: |
Sujith | d7ca213 | 2010-06-15 10:24:37 +0530 | [diff] [blame] | 1633 | ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid); |
| 1634 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1635 | break; |
| 1636 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
| 1637 | ista = (struct ath9k_htc_sta *) sta->drv_priv; |
Sujith Manoharan | 658ef04 | 2011-04-13 11:25:00 +0530 | [diff] [blame] | 1638 | spin_lock_bh(&priv->tx.tx_lock); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1639 | ista->tid_state[tid] = AGGR_OPERATIONAL; |
Sujith Manoharan | 658ef04 | 2011-04-13 11:25:00 +0530 | [diff] [blame] | 1640 | spin_unlock_bh(&priv->tx.tx_lock); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1641 | break; |
| 1642 | default: |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 1643 | ath_err(ath9k_hw_common(priv->ah), "Unknown AMPDU action\n"); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1644 | } |
| 1645 | |
Sujith Manoharan | c58ca5b | 2011-04-20 11:01:10 +0530 | [diff] [blame] | 1646 | ath9k_htc_ps_restore(priv); |
Sujith Manoharan | 87df895 | 2011-02-21 07:49:08 +0530 | [diff] [blame] | 1647 | mutex_unlock(&priv->mutex); |
| 1648 | |
Sujith | d7ca213 | 2010-06-15 10:24:37 +0530 | [diff] [blame] | 1649 | return ret; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1650 | } |
| 1651 | |
| 1652 | static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw) |
| 1653 | { |
| 1654 | struct ath9k_htc_priv *priv = hw->priv; |
| 1655 | |
| 1656 | mutex_lock(&priv->mutex); |
| 1657 | spin_lock_bh(&priv->beacon_lock); |
Sujith Manoharan | d8a2c51 | 2012-06-25 13:54:41 +0530 | [diff] [blame] | 1658 | set_bit(OP_SCANNING, &priv->op_flags); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1659 | spin_unlock_bh(&priv->beacon_lock); |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1660 | cancel_work_sync(&priv->ps_work); |
Sujith Manoharan | a236254 | 2011-02-21 07:49:38 +0530 | [diff] [blame] | 1661 | ath9k_htc_stop_ani(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1662 | mutex_unlock(&priv->mutex); |
| 1663 | } |
| 1664 | |
| 1665 | static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw) |
| 1666 | { |
| 1667 | struct ath9k_htc_priv *priv = hw->priv; |
| 1668 | |
| 1669 | mutex_lock(&priv->mutex); |
| 1670 | spin_lock_bh(&priv->beacon_lock); |
Sujith Manoharan | d8a2c51 | 2012-06-25 13:54:41 +0530 | [diff] [blame] | 1671 | clear_bit(OP_SCANNING, &priv->op_flags); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1672 | spin_unlock_bh(&priv->beacon_lock); |
Sujith Manoharan | 7c27734 | 2011-02-21 07:48:39 +0530 | [diff] [blame] | 1673 | ath9k_htc_ps_wakeup(priv); |
| 1674 | ath9k_htc_vif_reconfig(priv); |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 1675 | ath9k_htc_ps_restore(priv); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1676 | mutex_unlock(&priv->mutex); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1677 | } |
| 1678 | |
| 1679 | static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value) |
| 1680 | { |
| 1681 | return 0; |
| 1682 | } |
| 1683 | |
| 1684 | static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw, |
| 1685 | u8 coverage_class) |
| 1686 | { |
| 1687 | struct ath9k_htc_priv *priv = hw->priv; |
| 1688 | |
| 1689 | mutex_lock(&priv->mutex); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1690 | ath9k_htc_ps_wakeup(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1691 | priv->ah->coverage_class = coverage_class; |
| 1692 | ath9k_hw_init_global_settings(priv->ah); |
Sujith | cb551df | 2010-06-01 15:14:12 +0530 | [diff] [blame] | 1693 | ath9k_htc_ps_restore(priv); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1694 | mutex_unlock(&priv->mutex); |
| 1695 | } |
| 1696 | |
Sujith Manoharan | e2186b7 | 2011-04-27 17:13:40 +0530 | [diff] [blame] | 1697 | /* |
| 1698 | * Currently, this is used only for selecting the minimum rate |
| 1699 | * for management frames, rate selection for data frames remain |
| 1700 | * unaffected. |
| 1701 | */ |
| 1702 | static int ath9k_htc_set_bitrate_mask(struct ieee80211_hw *hw, |
| 1703 | struct ieee80211_vif *vif, |
| 1704 | const struct cfg80211_bitrate_mask *mask) |
| 1705 | { |
| 1706 | struct ath9k_htc_priv *priv = hw->priv; |
| 1707 | struct ath_common *common = ath9k_hw_common(priv->ah); |
| 1708 | struct ath9k_htc_target_rate_mask tmask; |
| 1709 | struct ath9k_htc_vif *avp = (void *)vif->drv_priv; |
| 1710 | int ret = 0; |
| 1711 | u8 cmd_rsp; |
| 1712 | |
| 1713 | memset(&tmask, 0, sizeof(struct ath9k_htc_target_rate_mask)); |
| 1714 | |
| 1715 | tmask.vif_index = avp->index; |
| 1716 | tmask.band = IEEE80211_BAND_2GHZ; |
| 1717 | tmask.mask = cpu_to_be32(mask->control[IEEE80211_BAND_2GHZ].legacy); |
| 1718 | |
| 1719 | WMI_CMD_BUF(WMI_BITRATE_MASK_CMDID, &tmask); |
| 1720 | if (ret) { |
| 1721 | ath_err(common, |
| 1722 | "Unable to set 2G rate mask for " |
| 1723 | "interface at idx: %d\n", avp->index); |
| 1724 | goto out; |
| 1725 | } |
| 1726 | |
| 1727 | tmask.band = IEEE80211_BAND_5GHZ; |
| 1728 | tmask.mask = cpu_to_be32(mask->control[IEEE80211_BAND_5GHZ].legacy); |
| 1729 | |
| 1730 | WMI_CMD_BUF(WMI_BITRATE_MASK_CMDID, &tmask); |
| 1731 | if (ret) { |
| 1732 | ath_err(common, |
| 1733 | "Unable to set 5G rate mask for " |
| 1734 | "interface at idx: %d\n", avp->index); |
| 1735 | goto out; |
| 1736 | } |
| 1737 | |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 1738 | ath_dbg(common, CONFIG, "Set bitrate masks: 0x%x, 0x%x\n", |
Sujith Manoharan | e2186b7 | 2011-04-27 17:13:40 +0530 | [diff] [blame] | 1739 | mask->control[IEEE80211_BAND_2GHZ].legacy, |
| 1740 | mask->control[IEEE80211_BAND_5GHZ].legacy); |
| 1741 | out: |
| 1742 | return ret; |
| 1743 | } |
| 1744 | |
Mohammed Shafi Shajakhan | 5fa7198 | 2011-08-25 01:01:22 +0530 | [diff] [blame] | 1745 | |
| 1746 | static int ath9k_htc_get_stats(struct ieee80211_hw *hw, |
| 1747 | struct ieee80211_low_level_stats *stats) |
| 1748 | { |
| 1749 | struct ath9k_htc_priv *priv = hw->priv; |
| 1750 | struct ath_hw *ah = priv->ah; |
| 1751 | struct ath9k_mib_stats *mib_stats = &ah->ah_mibStats; |
| 1752 | |
| 1753 | stats->dot11ACKFailureCount = mib_stats->ackrcv_bad; |
| 1754 | stats->dot11RTSFailureCount = mib_stats->rts_bad; |
| 1755 | stats->dot11FCSErrorCount = mib_stats->fcs_bad; |
| 1756 | stats->dot11RTSSuccessCount = mib_stats->rts_good; |
| 1757 | |
| 1758 | return 0; |
| 1759 | } |
| 1760 | |
Ben Greear | 156652b | 2013-06-19 14:02:14 -0700 | [diff] [blame] | 1761 | struct base_eep_header *ath9k_htc_get_eeprom_base(struct ath9k_htc_priv *priv) |
| 1762 | { |
| 1763 | struct base_eep_header *pBase = NULL; |
| 1764 | /* |
| 1765 | * This can be done since all the 3 EEPROM families have the |
| 1766 | * same base header upto a certain point, and we are interested in |
| 1767 | * the data only upto that point. |
| 1768 | */ |
| 1769 | |
| 1770 | if (AR_SREV_9271(priv->ah)) |
| 1771 | pBase = (struct base_eep_header *) |
| 1772 | &priv->ah->eeprom.map4k.baseEepHeader; |
| 1773 | else if (priv->ah->hw_version.usbdev == AR9280_USB) |
| 1774 | pBase = (struct base_eep_header *) |
| 1775 | &priv->ah->eeprom.def.baseEepHeader; |
| 1776 | else if (priv->ah->hw_version.usbdev == AR9287_USB) |
| 1777 | pBase = (struct base_eep_header *) |
| 1778 | &priv->ah->eeprom.map9287.baseEepHeader; |
| 1779 | return pBase; |
| 1780 | } |
| 1781 | |
| 1782 | |
| 1783 | static int ath9k_htc_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, |
| 1784 | u32 *rx_ant) |
| 1785 | { |
| 1786 | struct ath9k_htc_priv *priv = hw->priv; |
| 1787 | struct base_eep_header *pBase = ath9k_htc_get_eeprom_base(priv); |
| 1788 | if (pBase) { |
| 1789 | *tx_ant = pBase->txMask; |
| 1790 | *rx_ant = pBase->rxMask; |
| 1791 | } else { |
| 1792 | *tx_ant = 0; |
| 1793 | *rx_ant = 0; |
| 1794 | } |
| 1795 | return 0; |
| 1796 | } |
| 1797 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1798 | struct ieee80211_ops ath9k_htc_ops = { |
| 1799 | .tx = ath9k_htc_tx, |
| 1800 | .start = ath9k_htc_start, |
| 1801 | .stop = ath9k_htc_stop, |
| 1802 | .add_interface = ath9k_htc_add_interface, |
| 1803 | .remove_interface = ath9k_htc_remove_interface, |
| 1804 | .config = ath9k_htc_config, |
| 1805 | .configure_filter = ath9k_htc_configure_filter, |
Sujith | abd984e | 2010-05-18 15:26:04 +0530 | [diff] [blame] | 1806 | .sta_add = ath9k_htc_sta_add, |
| 1807 | .sta_remove = ath9k_htc_sta_remove, |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1808 | .conf_tx = ath9k_htc_conf_tx, |
Antonio Quartulli | 6957802 | 2012-08-12 19:36:41 +0200 | [diff] [blame] | 1809 | .sta_rc_update = ath9k_htc_sta_rc_update, |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1810 | .bss_info_changed = ath9k_htc_bss_info_changed, |
| 1811 | .set_key = ath9k_htc_set_key, |
| 1812 | .get_tsf = ath9k_htc_get_tsf, |
| 1813 | .set_tsf = ath9k_htc_set_tsf, |
| 1814 | .reset_tsf = ath9k_htc_reset_tsf, |
| 1815 | .ampdu_action = ath9k_htc_ampdu_action, |
| 1816 | .sw_scan_start = ath9k_htc_sw_scan_start, |
| 1817 | .sw_scan_complete = ath9k_htc_sw_scan_complete, |
| 1818 | .set_rts_threshold = ath9k_htc_set_rts_threshold, |
| 1819 | .rfkill_poll = ath9k_htc_rfkill_poll_state, |
| 1820 | .set_coverage_class = ath9k_htc_set_coverage_class, |
Sujith Manoharan | e2186b7 | 2011-04-27 17:13:40 +0530 | [diff] [blame] | 1821 | .set_bitrate_mask = ath9k_htc_set_bitrate_mask, |
Mohammed Shafi Shajakhan | 5fa7198 | 2011-08-25 01:01:22 +0530 | [diff] [blame] | 1822 | .get_stats = ath9k_htc_get_stats, |
Ben Greear | 156652b | 2013-06-19 14:02:14 -0700 | [diff] [blame] | 1823 | .get_antenna = ath9k_htc_get_antenna, |
Ben Greear | 68185a4 | 2013-06-19 14:02:15 -0700 | [diff] [blame] | 1824 | |
| 1825 | #ifdef CONFIG_ATH9K_HTC_DEBUGFS |
| 1826 | .get_et_sset_count = ath9k_htc_get_et_sset_count, |
| 1827 | .get_et_stats = ath9k_htc_get_et_stats, |
| 1828 | .get_et_strings = ath9k_htc_get_et_strings, |
| 1829 | #endif |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1830 | }; |