Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Wey-Yi Guy | 4e31826 | 2011-12-27 11:21:32 -0800 | [diff] [blame] | 3 | * Copyright(c) 2003 - 2012 Intel Corporation. All rights reserved. |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 4 | * |
| 5 | * Portions of this file are derived from the ipw3945 project, as well |
| 6 | * as portions of the ieee80211 subsystem header files. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of version 2 of the GNU General Public License as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 15 | * more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along with |
| 18 | * this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA |
| 20 | * |
| 21 | * The full GNU General Public License is included in this distribution in the |
| 22 | * file called LICENSE. |
| 23 | * |
| 24 | * Contact Information: |
| 25 | * Intel Linux Wireless <ilw@linux.intel.com> |
| 26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 27 | * |
| 28 | *****************************************************************************/ |
| 29 | #include <linux/kernel.h> |
| 30 | #include <linux/module.h> |
| 31 | #include <linux/init.h> |
| 32 | #include <linux/slab.h> |
| 33 | #include <linux/dma-mapping.h> |
| 34 | #include <linux/delay.h> |
| 35 | #include <linux/sched.h> |
| 36 | #include <linux/skbuff.h> |
| 37 | #include <linux/netdevice.h> |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 38 | #include <linux/etherdevice.h> |
| 39 | #include <linux/if_arp.h> |
| 40 | |
| 41 | #include <net/mac80211.h> |
| 42 | |
| 43 | #include <asm/div64.h> |
| 44 | |
| 45 | #include "iwl-eeprom.h" |
| 46 | #include "iwl-dev.h" |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 47 | #include "iwl-io.h" |
| 48 | #include "iwl-agn-calib.h" |
| 49 | #include "iwl-agn.h" |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 50 | #include "iwl-trans.h" |
Emmanuel Grumbach | d0f76d6 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 51 | #include "iwl-op-mode.h" |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 52 | |
| 53 | /***************************************************************************** |
| 54 | * |
| 55 | * mac80211 entry point functions |
| 56 | * |
| 57 | *****************************************************************************/ |
| 58 | |
| 59 | static const struct ieee80211_iface_limit iwlagn_sta_ap_limits[] = { |
| 60 | { |
| 61 | .max = 1, |
| 62 | .types = BIT(NL80211_IFTYPE_STATION), |
| 63 | }, |
| 64 | { |
| 65 | .max = 1, |
| 66 | .types = BIT(NL80211_IFTYPE_AP), |
| 67 | }, |
| 68 | }; |
| 69 | |
| 70 | static const struct ieee80211_iface_limit iwlagn_2sta_limits[] = { |
| 71 | { |
| 72 | .max = 2, |
| 73 | .types = BIT(NL80211_IFTYPE_STATION), |
| 74 | }, |
| 75 | }; |
| 76 | |
| 77 | static const struct ieee80211_iface_limit iwlagn_p2p_sta_go_limits[] = { |
| 78 | { |
| 79 | .max = 1, |
| 80 | .types = BIT(NL80211_IFTYPE_STATION), |
| 81 | }, |
| 82 | { |
| 83 | .max = 1, |
| 84 | .types = BIT(NL80211_IFTYPE_P2P_GO) | |
| 85 | BIT(NL80211_IFTYPE_AP), |
| 86 | }, |
| 87 | }; |
| 88 | |
| 89 | static const struct ieee80211_iface_limit iwlagn_p2p_2sta_limits[] = { |
| 90 | { |
| 91 | .max = 2, |
| 92 | .types = BIT(NL80211_IFTYPE_STATION), |
| 93 | }, |
| 94 | { |
| 95 | .max = 1, |
| 96 | .types = BIT(NL80211_IFTYPE_P2P_CLIENT), |
| 97 | }, |
| 98 | }; |
| 99 | |
| 100 | static const struct ieee80211_iface_combination |
| 101 | iwlagn_iface_combinations_dualmode[] = { |
| 102 | { .num_different_channels = 1, |
| 103 | .max_interfaces = 2, |
| 104 | .beacon_int_infra_match = true, |
| 105 | .limits = iwlagn_sta_ap_limits, |
| 106 | .n_limits = ARRAY_SIZE(iwlagn_sta_ap_limits), |
| 107 | }, |
| 108 | { .num_different_channels = 1, |
| 109 | .max_interfaces = 2, |
| 110 | .limits = iwlagn_2sta_limits, |
| 111 | .n_limits = ARRAY_SIZE(iwlagn_2sta_limits), |
| 112 | }, |
| 113 | }; |
| 114 | |
| 115 | static const struct ieee80211_iface_combination |
| 116 | iwlagn_iface_combinations_p2p[] = { |
| 117 | { .num_different_channels = 1, |
| 118 | .max_interfaces = 2, |
| 119 | .beacon_int_infra_match = true, |
| 120 | .limits = iwlagn_p2p_sta_go_limits, |
| 121 | .n_limits = ARRAY_SIZE(iwlagn_p2p_sta_go_limits), |
| 122 | }, |
| 123 | { .num_different_channels = 1, |
| 124 | .max_interfaces = 2, |
| 125 | .limits = iwlagn_p2p_2sta_limits, |
| 126 | .n_limits = ARRAY_SIZE(iwlagn_p2p_2sta_limits), |
| 127 | }, |
| 128 | }; |
| 129 | |
| 130 | /* |
| 131 | * Not a mac80211 entry point function, but it fits in with all the |
| 132 | * other mac80211 functions grouped here. |
| 133 | */ |
| 134 | int iwlagn_mac_setup_register(struct iwl_priv *priv, |
Johannes Berg | 0692fe4 | 2012-03-06 13:30:37 -0800 | [diff] [blame] | 135 | const struct iwl_ucode_capabilities *capa) |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 136 | { |
| 137 | int ret; |
| 138 | struct ieee80211_hw *hw = priv->hw; |
| 139 | struct iwl_rxon_context *ctx; |
| 140 | |
| 141 | hw->rate_control_algorithm = "iwl-agn-rs"; |
| 142 | |
| 143 | /* Tell mac80211 our characteristics */ |
| 144 | hw->flags = IEEE80211_HW_SIGNAL_DBM | |
| 145 | IEEE80211_HW_AMPDU_AGGREGATION | |
| 146 | IEEE80211_HW_NEED_DTIM_PERIOD | |
| 147 | IEEE80211_HW_SPECTRUM_MGMT | |
| 148 | IEEE80211_HW_REPORTS_TX_ACK_STATUS; |
| 149 | |
| 150 | /* |
| 151 | * Including the following line will crash some AP's. This |
| 152 | * workaround removes the stimulus which causes the crash until |
| 153 | * the AP software can be fixed. |
| 154 | hw->max_tx_aggregation_subframes = LINK_QUAL_AGG_FRAME_LIMIT_DEF; |
| 155 | */ |
| 156 | |
| 157 | hw->flags |= IEEE80211_HW_SUPPORTS_PS | |
Johannes Berg | e561038 | 2012-03-15 13:26:51 -0700 | [diff] [blame] | 158 | IEEE80211_HW_SUPPORTS_DYNAMIC_PS | |
| 159 | IEEE80211_HW_SCAN_WHILE_IDLE; |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 160 | |
Johannes Berg | 9e29511 | 2012-04-09 17:46:55 -0700 | [diff] [blame] | 161 | if (priv->hw_params.sku & EEPROM_SKU_CAP_11N_ENABLE) |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 162 | hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS | |
| 163 | IEEE80211_HW_SUPPORTS_STATIC_SMPS; |
| 164 | |
David Spinadel | 18c57d3 | 2012-03-07 09:52:31 -0800 | [diff] [blame] | 165 | #ifndef CONFIG_IWLWIFI_EXPERIMENTAL_MFP |
| 166 | /* enable 11w if the uCode advertise */ |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 167 | if (capa->flags & IWL_UCODE_TLV_FLAGS_MFP) |
David Spinadel | 18c57d3 | 2012-03-07 09:52:31 -0800 | [diff] [blame] | 168 | #endif /* !CONFIG_IWLWIFI_EXPERIMENTAL_MFP */ |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 169 | hw->flags |= IEEE80211_HW_MFP_CAPABLE; |
| 170 | |
| 171 | hw->sta_data_size = sizeof(struct iwl_station_priv); |
| 172 | hw->vif_data_size = sizeof(struct iwl_vif_priv); |
| 173 | |
| 174 | for_each_context(priv, ctx) { |
| 175 | hw->wiphy->interface_modes |= ctx->interface_modes; |
| 176 | hw->wiphy->interface_modes |= ctx->exclusive_interface_modes; |
| 177 | } |
| 178 | |
| 179 | BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2); |
| 180 | |
| 181 | if (hw->wiphy->interface_modes & BIT(NL80211_IFTYPE_P2P_CLIENT)) { |
| 182 | hw->wiphy->iface_combinations = iwlagn_iface_combinations_p2p; |
| 183 | hw->wiphy->n_iface_combinations = |
| 184 | ARRAY_SIZE(iwlagn_iface_combinations_p2p); |
| 185 | } else if (hw->wiphy->interface_modes & BIT(NL80211_IFTYPE_AP)) { |
| 186 | hw->wiphy->iface_combinations = |
| 187 | iwlagn_iface_combinations_dualmode; |
| 188 | hw->wiphy->n_iface_combinations = |
| 189 | ARRAY_SIZE(iwlagn_iface_combinations_dualmode); |
| 190 | } |
| 191 | |
| 192 | hw->wiphy->max_remain_on_channel_duration = 1000; |
| 193 | |
| 194 | hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY | |
| 195 | WIPHY_FLAG_DISABLE_BEACON_HINTS | |
| 196 | WIPHY_FLAG_IBSS_RSN; |
| 197 | |
David Spinadel | 6dfa8d0 | 2012-03-10 13:00:14 -0800 | [diff] [blame] | 198 | if (priv->fw->img[IWL_UCODE_WOWLAN].sec[0].len && |
Emmanuel Grumbach | 68e8dfd | 2012-04-18 07:28:17 -0700 | [diff] [blame] | 199 | priv->trans->ops->wowlan_suspend && |
| 200 | device_can_wakeup(priv->trans->dev)) { |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 201 | hw->wiphy->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT | |
| 202 | WIPHY_WOWLAN_DISCONNECT | |
| 203 | WIPHY_WOWLAN_EAP_IDENTITY_REQ | |
| 204 | WIPHY_WOWLAN_RFKILL_RELEASE; |
| 205 | if (!iwlagn_mod_params.sw_crypto) |
| 206 | hw->wiphy->wowlan.flags |= |
| 207 | WIPHY_WOWLAN_SUPPORTS_GTK_REKEY | |
| 208 | WIPHY_WOWLAN_GTK_REKEY_FAILURE; |
| 209 | |
| 210 | hw->wiphy->wowlan.n_patterns = IWLAGN_WOWLAN_MAX_PATTERNS; |
| 211 | hw->wiphy->wowlan.pattern_min_len = |
| 212 | IWLAGN_WOWLAN_MIN_PATTERN_LEN; |
| 213 | hw->wiphy->wowlan.pattern_max_len = |
| 214 | IWLAGN_WOWLAN_MAX_PATTERN_LEN; |
| 215 | } |
| 216 | |
| 217 | if (iwlagn_mod_params.power_save) |
| 218 | hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT; |
| 219 | else |
| 220 | hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT; |
| 221 | |
| 222 | hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX; |
| 223 | /* we create the 802.11 header and a zero-length SSID element */ |
| 224 | hw->wiphy->max_scan_ie_len = capa->max_probe_length - 24 - 2; |
| 225 | |
| 226 | /* Default value; 4 EDCA QOS priorities */ |
| 227 | hw->queues = 4; |
| 228 | |
| 229 | hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL; |
| 230 | |
| 231 | if (priv->bands[IEEE80211_BAND_2GHZ].n_channels) |
| 232 | priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = |
| 233 | &priv->bands[IEEE80211_BAND_2GHZ]; |
| 234 | if (priv->bands[IEEE80211_BAND_5GHZ].n_channels) |
| 235 | priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = |
| 236 | &priv->bands[IEEE80211_BAND_5GHZ]; |
| 237 | |
Emmanuel Grumbach | 68e8dfd | 2012-04-18 07:28:17 -0700 | [diff] [blame] | 238 | hw->wiphy->hw_version = priv->trans->hw_id; |
Wey-Yi Guy | 0ba958e | 2011-12-10 11:33:52 -0800 | [diff] [blame] | 239 | |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 240 | iwl_leds_init(priv); |
| 241 | |
| 242 | ret = ieee80211_register_hw(priv->hw); |
| 243 | if (ret) { |
| 244 | IWL_ERR(priv, "Failed to register hw (error %d)\n", ret); |
| 245 | return ret; |
| 246 | } |
| 247 | priv->mac80211_registered = 1; |
| 248 | |
| 249 | return 0; |
| 250 | } |
| 251 | |
Don Fry | 09af140 | 2011-12-09 10:07:38 -0800 | [diff] [blame] | 252 | void iwlagn_mac_unregister(struct iwl_priv *priv) |
| 253 | { |
| 254 | if (!priv->mac80211_registered) |
| 255 | return; |
| 256 | iwl_leds_exit(priv); |
| 257 | ieee80211_unregister_hw(priv->hw); |
| 258 | priv->mac80211_registered = 0; |
| 259 | } |
| 260 | |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 261 | static int __iwl_up(struct iwl_priv *priv) |
| 262 | { |
| 263 | struct iwl_rxon_context *ctx; |
| 264 | int ret; |
| 265 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 266 | lockdep_assert_held(&priv->mutex); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 267 | |
Don Fry | 8362640 | 2012-03-07 09:52:37 -0800 | [diff] [blame] | 268 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 269 | IWL_WARN(priv, "Exit pending; will not bring the NIC up\n"); |
| 270 | return -EIO; |
| 271 | } |
| 272 | |
| 273 | for_each_context(priv, ctx) { |
| 274 | ret = iwlagn_alloc_bcast_station(priv, ctx); |
| 275 | if (ret) { |
| 276 | iwl_dealloc_bcast_stations(priv); |
| 277 | return ret; |
| 278 | } |
| 279 | } |
| 280 | |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 281 | ret = iwl_run_init_ucode(priv); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 282 | if (ret) { |
| 283 | IWL_ERR(priv, "Failed to run INIT ucode: %d\n", ret); |
| 284 | goto error; |
| 285 | } |
| 286 | |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 287 | ret = iwl_load_ucode_wait_alive(priv, IWL_UCODE_REGULAR); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 288 | if (ret) { |
| 289 | IWL_ERR(priv, "Failed to start RT ucode: %d\n", ret); |
| 290 | goto error; |
| 291 | } |
| 292 | |
| 293 | ret = iwl_alive_start(priv); |
| 294 | if (ret) |
| 295 | goto error; |
| 296 | return 0; |
| 297 | |
| 298 | error: |
Don Fry | 8362640 | 2012-03-07 09:52:37 -0800 | [diff] [blame] | 299 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Emmanuel Grumbach | 78e5a46 | 2012-02-17 10:34:53 -0800 | [diff] [blame] | 300 | iwl_down(priv); |
Don Fry | 8362640 | 2012-03-07 09:52:37 -0800 | [diff] [blame] | 301 | clear_bit(STATUS_EXIT_PENDING, &priv->status); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 302 | |
| 303 | IWL_ERR(priv, "Unable to initialize device.\n"); |
| 304 | return ret; |
| 305 | } |
| 306 | |
| 307 | static int iwlagn_mac_start(struct ieee80211_hw *hw) |
| 308 | { |
Emmanuel Grumbach | d0f76d6 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 309 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 310 | int ret; |
| 311 | |
| 312 | IWL_DEBUG_MAC80211(priv, "enter\n"); |
| 313 | |
| 314 | /* we should be verifying the device is ready to be opened */ |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 315 | mutex_lock(&priv->mutex); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 316 | ret = __iwl_up(priv); |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 317 | mutex_unlock(&priv->mutex); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 318 | if (ret) |
| 319 | return ret; |
| 320 | |
| 321 | IWL_DEBUG_INFO(priv, "Start UP work done.\n"); |
| 322 | |
| 323 | /* Now we should be done, and the READY bit should be set. */ |
Don Fry | 8362640 | 2012-03-07 09:52:37 -0800 | [diff] [blame] | 324 | if (WARN_ON(!test_bit(STATUS_READY, &priv->status))) |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 325 | ret = -EIO; |
| 326 | |
| 327 | iwlagn_led_enable(priv); |
| 328 | |
| 329 | priv->is_open = 1; |
| 330 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
| 331 | return 0; |
| 332 | } |
| 333 | |
David Spinadel | 50c1e9a | 2012-04-16 14:43:30 -0700 | [diff] [blame] | 334 | void iwlagn_mac_stop(struct ieee80211_hw *hw) |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 335 | { |
Emmanuel Grumbach | d0f76d6 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 336 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 337 | |
| 338 | IWL_DEBUG_MAC80211(priv, "enter\n"); |
| 339 | |
| 340 | if (!priv->is_open) |
| 341 | return; |
| 342 | |
| 343 | priv->is_open = 0; |
| 344 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 345 | mutex_lock(&priv->mutex); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 346 | iwl_down(priv); |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 347 | mutex_unlock(&priv->mutex); |
Emmanuel Grumbach | 78e5a46 | 2012-02-17 10:34:53 -0800 | [diff] [blame] | 348 | |
| 349 | iwl_cancel_deferred_work(priv); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 350 | |
Johannes Berg | 1ee158d | 2012-02-17 10:07:44 -0800 | [diff] [blame] | 351 | flush_workqueue(priv->workqueue); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 352 | |
| 353 | /* User space software may expect getting rfkill changes |
Emmanuel Grumbach | 1df06bd | 2012-01-09 16:35:08 +0200 | [diff] [blame] | 354 | * even if interface is down, trans->down will leave the RF |
| 355 | * kill interrupt enabled |
| 356 | */ |
Emmanuel Grumbach | 218733c | 2012-03-31 08:28:38 -0700 | [diff] [blame] | 357 | iwl_trans_stop_hw(priv->trans, false); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 358 | |
| 359 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
| 360 | } |
| 361 | |
David Spinadel | 50c1e9a | 2012-04-16 14:43:30 -0700 | [diff] [blame] | 362 | void iwlagn_mac_set_rekey_data(struct ieee80211_hw *hw, |
| 363 | struct ieee80211_vif *vif, |
| 364 | struct cfg80211_gtk_rekey_data *data) |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 365 | { |
Emmanuel Grumbach | d0f76d6 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 366 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 367 | |
| 368 | if (iwlagn_mod_params.sw_crypto) |
| 369 | return; |
| 370 | |
| 371 | IWL_DEBUG_MAC80211(priv, "enter\n"); |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 372 | mutex_lock(&priv->mutex); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 373 | |
| 374 | if (priv->contexts[IWL_RXON_CTX_BSS].vif != vif) |
| 375 | goto out; |
| 376 | |
| 377 | memcpy(priv->kek, data->kek, NL80211_KEK_LEN); |
| 378 | memcpy(priv->kck, data->kck, NL80211_KCK_LEN); |
| 379 | priv->replay_ctr = |
| 380 | cpu_to_le64(be64_to_cpup((__be64 *)&data->replay_ctr)); |
| 381 | priv->have_rekey_data = true; |
| 382 | |
| 383 | out: |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 384 | mutex_unlock(&priv->mutex); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 385 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
| 386 | } |
| 387 | |
| 388 | #ifdef CONFIG_PM_SLEEP |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 389 | |
David Spinadel | 50c1e9a | 2012-04-16 14:43:30 -0700 | [diff] [blame] | 390 | int iwlagn_mac_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan) |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 391 | { |
Emmanuel Grumbach | d0f76d6 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 392 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 393 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; |
Wey-Yi Guy | 023ca58 | 2011-11-10 06:55:17 -0800 | [diff] [blame] | 394 | int ret; |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 395 | |
| 396 | if (WARN_ON(!wowlan)) |
| 397 | return -EINVAL; |
| 398 | |
| 399 | IWL_DEBUG_MAC80211(priv, "enter\n"); |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 400 | mutex_lock(&priv->mutex); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 401 | |
| 402 | /* Don't attempt WoWLAN when not associated, tear down instead. */ |
| 403 | if (!ctx->vif || ctx->vif->type != NL80211_IFTYPE_STATION || |
| 404 | !iwl_is_associated_ctx(ctx)) { |
| 405 | ret = 1; |
| 406 | goto out; |
| 407 | } |
| 408 | |
Johannes Berg | ea886a6 | 2012-03-07 09:52:15 -0800 | [diff] [blame] | 409 | ret = iwlagn_suspend(priv, wowlan); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 410 | if (ret) |
| 411 | goto error; |
| 412 | |
Emmanuel Grumbach | 68e8dfd | 2012-04-18 07:28:17 -0700 | [diff] [blame] | 413 | device_set_wakeup_enable(priv->trans->dev, true); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 414 | |
Emmanuel Grumbach | 68e8dfd | 2012-04-18 07:28:17 -0700 | [diff] [blame] | 415 | iwl_trans_wowlan_suspend(priv->trans); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 416 | |
| 417 | goto out; |
| 418 | |
| 419 | error: |
Johannes Berg | 15b86bf | 2012-03-05 11:24:36 -0800 | [diff] [blame] | 420 | priv->wowlan = false; |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 421 | iwlagn_prepare_restart(priv); |
| 422 | ieee80211_restart_hw(priv->hw); |
| 423 | out: |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 424 | mutex_unlock(&priv->mutex); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 425 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
| 426 | |
| 427 | return ret; |
| 428 | } |
| 429 | |
| 430 | static int iwlagn_mac_resume(struct ieee80211_hw *hw) |
| 431 | { |
Emmanuel Grumbach | d0f76d6 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 432 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 433 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; |
| 434 | struct ieee80211_vif *vif; |
| 435 | unsigned long flags; |
| 436 | u32 base, status = 0xffffffff; |
| 437 | int ret = -EIO; |
| 438 | |
| 439 | IWL_DEBUG_MAC80211(priv, "enter\n"); |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 440 | mutex_lock(&priv->mutex); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 441 | |
Emmanuel Grumbach | 68e8dfd | 2012-04-18 07:28:17 -0700 | [diff] [blame] | 442 | iwl_write32(priv->trans, CSR_UCODE_DRV_GP1_CLR, |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 443 | CSR_UCODE_DRV_GP1_BIT_D3_CFG_COMPLETE); |
| 444 | |
Meenakshi Venkataraman | 2fdfc47 | 2012-03-15 13:26:56 -0700 | [diff] [blame] | 445 | base = priv->device_pointers.error_event_table; |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 446 | if (iwlagn_hw_valid_rtc_data_addr(base)) { |
Emmanuel Grumbach | 68e8dfd | 2012-04-18 07:28:17 -0700 | [diff] [blame] | 447 | spin_lock_irqsave(&priv->trans->reg_lock, flags); |
| 448 | ret = iwl_grab_nic_access_silent(priv->trans); |
Stanislaw Gruszka | bfe4b80 | 2012-03-07 09:52:24 -0800 | [diff] [blame] | 449 | if (likely(ret == 0)) { |
Emmanuel Grumbach | 68e8dfd | 2012-04-18 07:28:17 -0700 | [diff] [blame] | 450 | iwl_write32(priv->trans, HBUS_TARG_MEM_RADDR, base); |
| 451 | status = iwl_read32(priv->trans, HBUS_TARG_MEM_RDAT); |
| 452 | iwl_release_nic_access(priv->trans); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 453 | } |
Emmanuel Grumbach | 68e8dfd | 2012-04-18 07:28:17 -0700 | [diff] [blame] | 454 | spin_unlock_irqrestore(&priv->trans->reg_lock, flags); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 455 | |
| 456 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 457 | if (ret == 0) { |
Oliver Hartkopp | a855f7e | 2012-03-25 08:43:24 +0200 | [diff] [blame] | 458 | const struct fw_img *img; |
| 459 | |
David Spinadel | 6dfa8d0 | 2012-03-10 13:00:14 -0800 | [diff] [blame] | 460 | img = &(priv->fw->img[IWL_UCODE_WOWLAN]); |
| 461 | if (!priv->wowlan_sram) { |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 462 | priv->wowlan_sram = |
David Spinadel | 6dfa8d0 | 2012-03-10 13:00:14 -0800 | [diff] [blame] | 463 | kzalloc(img->sec[IWL_UCODE_SECTION_DATA].len, |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 464 | GFP_KERNEL); |
David Spinadel | 6dfa8d0 | 2012-03-10 13:00:14 -0800 | [diff] [blame] | 465 | } |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 466 | |
| 467 | if (priv->wowlan_sram) |
| 468 | _iwl_read_targ_mem_words( |
Emmanuel Grumbach | 68e8dfd | 2012-04-18 07:28:17 -0700 | [diff] [blame] | 469 | priv->trans, 0x800000, |
David Spinadel | 6dfa8d0 | 2012-03-10 13:00:14 -0800 | [diff] [blame] | 470 | priv->wowlan_sram, |
| 471 | img->sec[IWL_UCODE_SECTION_DATA].len / 4); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 472 | } |
| 473 | #endif |
| 474 | } |
| 475 | |
| 476 | /* we'll clear ctx->vif during iwlagn_prepare_restart() */ |
| 477 | vif = ctx->vif; |
| 478 | |
Johannes Berg | 15b86bf | 2012-03-05 11:24:36 -0800 | [diff] [blame] | 479 | priv->wowlan = false; |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 480 | |
Emmanuel Grumbach | 68e8dfd | 2012-04-18 07:28:17 -0700 | [diff] [blame] | 481 | device_set_wakeup_enable(priv->trans->dev, false); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 482 | |
| 483 | iwlagn_prepare_restart(priv); |
| 484 | |
| 485 | memset((void *)&ctx->active, 0, sizeof(ctx->active)); |
| 486 | iwl_connection_init_rx_config(priv, ctx); |
| 487 | iwlagn_set_rxon_chain(priv, ctx); |
| 488 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 489 | mutex_unlock(&priv->mutex); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 490 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
| 491 | |
| 492 | ieee80211_resume_disconnect(vif); |
| 493 | |
| 494 | return 1; |
| 495 | } |
| 496 | |
| 497 | #endif |
| 498 | |
David Spinadel | 50c1e9a | 2012-04-16 14:43:30 -0700 | [diff] [blame] | 499 | void iwlagn_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb) |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 500 | { |
Emmanuel Grumbach | d0f76d6 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 501 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 502 | |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 503 | IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len, |
| 504 | ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate); |
| 505 | |
| 506 | if (iwlagn_tx_skb(priv, skb)) |
| 507 | dev_kfree_skb_any(skb); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 508 | } |
| 509 | |
David Spinadel | 50c1e9a | 2012-04-16 14:43:30 -0700 | [diff] [blame] | 510 | void iwlagn_mac_update_tkip_key(struct ieee80211_hw *hw, |
| 511 | struct ieee80211_vif *vif, |
| 512 | struct ieee80211_key_conf *keyconf, |
| 513 | struct ieee80211_sta *sta, |
| 514 | u32 iv32, u16 *phase1key) |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 515 | { |
Emmanuel Grumbach | d0f76d6 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 516 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 517 | |
| 518 | iwl_update_tkip_key(priv, vif, keyconf, sta, iv32, phase1key); |
| 519 | } |
| 520 | |
David Spinadel | 50c1e9a | 2012-04-16 14:43:30 -0700 | [diff] [blame] | 521 | int iwlagn_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, |
| 522 | struct ieee80211_vif *vif, |
| 523 | struct ieee80211_sta *sta, |
| 524 | struct ieee80211_key_conf *key) |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 525 | { |
Emmanuel Grumbach | d0f76d6 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 526 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 527 | struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv; |
| 528 | struct iwl_rxon_context *ctx = vif_priv->ctx; |
| 529 | int ret; |
| 530 | bool is_default_wep_key = false; |
| 531 | |
| 532 | IWL_DEBUG_MAC80211(priv, "enter\n"); |
| 533 | |
| 534 | if (iwlagn_mod_params.sw_crypto) { |
| 535 | IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n"); |
| 536 | return -EOPNOTSUPP; |
| 537 | } |
| 538 | |
Johannes Berg | a7e12c8 | 2011-11-25 03:20:09 -0800 | [diff] [blame] | 539 | switch (key->cipher) { |
| 540 | case WLAN_CIPHER_SUITE_TKIP: |
| 541 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; |
| 542 | /* fall through */ |
| 543 | case WLAN_CIPHER_SUITE_CCMP: |
| 544 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 545 | break; |
| 546 | default: |
| 547 | break; |
| 548 | } |
| 549 | |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 550 | /* |
| 551 | * We could program these keys into the hardware as well, but we |
| 552 | * don't expect much multicast traffic in IBSS and having keys |
| 553 | * for more stations is probably more useful. |
| 554 | * |
| 555 | * Mark key TX-only and return 0. |
| 556 | */ |
| 557 | if (vif->type == NL80211_IFTYPE_ADHOC && |
| 558 | !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) { |
| 559 | key->hw_key_idx = WEP_INVALID_OFFSET; |
| 560 | return 0; |
| 561 | } |
| 562 | |
| 563 | /* If they key was TX-only, accept deletion */ |
| 564 | if (cmd == DISABLE_KEY && key->hw_key_idx == WEP_INVALID_OFFSET) |
| 565 | return 0; |
| 566 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 567 | mutex_lock(&priv->mutex); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 568 | iwl_scan_cancel_timeout(priv, 100); |
| 569 | |
| 570 | BUILD_BUG_ON(WEP_INVALID_OFFSET == IWLAGN_HW_KEY_DEFAULT); |
| 571 | |
| 572 | /* |
| 573 | * If we are getting WEP group key and we didn't receive any key mapping |
| 574 | * so far, we are in legacy wep mode (group key only), otherwise we are |
| 575 | * in 1X mode. |
| 576 | * In legacy wep mode, we use another host command to the uCode. |
| 577 | */ |
| 578 | if ((key->cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 579 | key->cipher == WLAN_CIPHER_SUITE_WEP104) && !sta) { |
| 580 | if (cmd == SET_KEY) |
| 581 | is_default_wep_key = !ctx->key_mapping_keys; |
| 582 | else |
| 583 | is_default_wep_key = |
| 584 | key->hw_key_idx == IWLAGN_HW_KEY_DEFAULT; |
| 585 | } |
| 586 | |
| 587 | |
| 588 | switch (cmd) { |
| 589 | case SET_KEY: |
| 590 | if (is_default_wep_key) { |
| 591 | ret = iwl_set_default_wep_key(priv, vif_priv->ctx, key); |
| 592 | break; |
| 593 | } |
| 594 | ret = iwl_set_dynamic_key(priv, vif_priv->ctx, key, sta); |
| 595 | if (ret) { |
| 596 | /* |
| 597 | * can't add key for RX, but we don't need it |
| 598 | * in the device for TX so still return 0 |
| 599 | */ |
| 600 | ret = 0; |
| 601 | key->hw_key_idx = WEP_INVALID_OFFSET; |
| 602 | } |
| 603 | |
| 604 | IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n"); |
| 605 | break; |
| 606 | case DISABLE_KEY: |
| 607 | if (is_default_wep_key) |
| 608 | ret = iwl_remove_default_wep_key(priv, ctx, key); |
| 609 | else |
| 610 | ret = iwl_remove_dynamic_key(priv, ctx, key, sta); |
| 611 | |
| 612 | IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n"); |
| 613 | break; |
| 614 | default: |
| 615 | ret = -EINVAL; |
| 616 | } |
| 617 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 618 | mutex_unlock(&priv->mutex); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 619 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
| 620 | |
| 621 | return ret; |
| 622 | } |
| 623 | |
David Spinadel | 50c1e9a | 2012-04-16 14:43:30 -0700 | [diff] [blame] | 624 | int iwlagn_mac_ampdu_action(struct ieee80211_hw *hw, |
| 625 | struct ieee80211_vif *vif, |
| 626 | enum ieee80211_ampdu_mlme_action action, |
| 627 | struct ieee80211_sta *sta, u16 tid, u16 *ssn, |
| 628 | u8 buf_size) |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 629 | { |
Emmanuel Grumbach | d0f76d6 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 630 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 631 | int ret = -EINVAL; |
| 632 | struct iwl_station_priv *sta_priv = (void *) sta->drv_priv; |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 633 | |
| 634 | IWL_DEBUG_HT(priv, "A-MPDU action on addr %pM tid %d\n", |
| 635 | sta->addr, tid); |
| 636 | |
Johannes Berg | 9e29511 | 2012-04-09 17:46:55 -0700 | [diff] [blame] | 637 | if (!(priv->hw_params.sku & EEPROM_SKU_CAP_11N_ENABLE)) |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 638 | return -EACCES; |
| 639 | |
| 640 | IWL_DEBUG_MAC80211(priv, "enter\n"); |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 641 | mutex_lock(&priv->mutex); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 642 | |
| 643 | switch (action) { |
| 644 | case IEEE80211_AMPDU_RX_START: |
Johannes Berg | 7428994 | 2011-12-13 00:07:40 -0800 | [diff] [blame] | 645 | if (iwlagn_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG) |
| 646 | break; |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 647 | IWL_DEBUG_HT(priv, "start Rx\n"); |
| 648 | ret = iwl_sta_rx_agg_start(priv, sta, tid, *ssn); |
| 649 | break; |
| 650 | case IEEE80211_AMPDU_RX_STOP: |
| 651 | IWL_DEBUG_HT(priv, "stop Rx\n"); |
| 652 | ret = iwl_sta_rx_agg_stop(priv, sta, tid); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 653 | break; |
| 654 | case IEEE80211_AMPDU_TX_START: |
Emmanuel Grumbach | 68e8dfd | 2012-04-18 07:28:17 -0700 | [diff] [blame] | 655 | if (!priv->trans->ops->tx_agg_setup) |
Johannes Berg | 9eae88f | 2012-03-15 13:26:52 -0700 | [diff] [blame] | 656 | break; |
Johannes Berg | 7428994 | 2011-12-13 00:07:40 -0800 | [diff] [blame] | 657 | if (iwlagn_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG) |
| 658 | break; |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 659 | IWL_DEBUG_HT(priv, "start Tx\n"); |
| 660 | ret = iwlagn_tx_agg_start(priv, vif, sta, tid, ssn); |
| 661 | break; |
| 662 | case IEEE80211_AMPDU_TX_STOP: |
| 663 | IWL_DEBUG_HT(priv, "stop Tx\n"); |
| 664 | ret = iwlagn_tx_agg_stop(priv, vif, sta, tid); |
| 665 | if ((ret == 0) && (priv->agg_tids_count > 0)) { |
| 666 | priv->agg_tids_count--; |
| 667 | IWL_DEBUG_HT(priv, "priv->agg_tids_count = %u\n", |
| 668 | priv->agg_tids_count); |
| 669 | } |
Johannes Berg | b9ad70d | 2012-03-06 13:30:55 -0800 | [diff] [blame] | 670 | if (!priv->agg_tids_count && |
Johannes Berg | 9e29511 | 2012-04-09 17:46:55 -0700 | [diff] [blame] | 671 | priv->hw_params.use_rts_for_aggregation) { |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 672 | /* |
| 673 | * switch off RTS/CTS if it was previously enabled |
| 674 | */ |
| 675 | sta_priv->lq_sta.lq.general_params.flags &= |
| 676 | ~LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK; |
| 677 | iwl_send_lq_cmd(priv, iwl_rxon_ctx_from_vif(vif), |
| 678 | &sta_priv->lq_sta.lq, CMD_ASYNC, false); |
| 679 | } |
| 680 | break; |
| 681 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
Emmanuel Grumbach | 822e8b2 | 2011-11-21 13:25:31 +0200 | [diff] [blame] | 682 | ret = iwlagn_tx_agg_oper(priv, vif, sta, tid, buf_size); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 683 | break; |
| 684 | } |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 685 | mutex_unlock(&priv->mutex); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 686 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
| 687 | return ret; |
| 688 | } |
| 689 | |
| 690 | static int iwlagn_mac_sta_add(struct ieee80211_hw *hw, |
| 691 | struct ieee80211_vif *vif, |
| 692 | struct ieee80211_sta *sta) |
| 693 | { |
Emmanuel Grumbach | d0f76d6 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 694 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 695 | struct iwl_station_priv *sta_priv = (void *)sta->drv_priv; |
| 696 | struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv; |
| 697 | bool is_ap = vif->type == NL80211_IFTYPE_STATION; |
Johannes Berg | fb5fe5b | 2012-03-05 11:24:29 -0800 | [diff] [blame] | 698 | int ret; |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 699 | u8 sta_id; |
| 700 | |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 701 | IWL_DEBUG_INFO(priv, "proceeding to add station %pM\n", |
| 702 | sta->addr); |
| 703 | sta_priv->sta_id = IWL_INVALID_STATION; |
| 704 | |
| 705 | atomic_set(&sta_priv->pending_frames, 0); |
| 706 | if (vif->type == NL80211_IFTYPE_AP) |
| 707 | sta_priv->client = true; |
| 708 | |
| 709 | ret = iwl_add_station_common(priv, vif_priv->ctx, sta->addr, |
| 710 | is_ap, sta, &sta_id); |
| 711 | if (ret) { |
| 712 | IWL_ERR(priv, "Unable to add station %pM (%d)\n", |
| 713 | sta->addr, ret); |
| 714 | /* Should we return success if return code is EEXIST ? */ |
Johannes Berg | fb5fe5b | 2012-03-05 11:24:29 -0800 | [diff] [blame] | 715 | return ret; |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | sta_priv->sta_id = sta_id; |
| 719 | |
Johannes Berg | fb5fe5b | 2012-03-05 11:24:29 -0800 | [diff] [blame] | 720 | return 0; |
| 721 | } |
| 722 | |
| 723 | static int iwlagn_mac_sta_remove(struct ieee80211_hw *hw, |
| 724 | struct ieee80211_vif *vif, |
| 725 | struct ieee80211_sta *sta) |
| 726 | { |
| 727 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
| 728 | struct iwl_station_priv *sta_priv = (void *)sta->drv_priv; |
| 729 | int ret; |
| 730 | |
Johannes Berg | 9742051 | 2012-03-07 09:52:42 -0800 | [diff] [blame] | 731 | IWL_DEBUG_INFO(priv, "proceeding to remove station %pM\n", sta->addr); |
| 732 | |
| 733 | if (vif->type == NL80211_IFTYPE_STATION) { |
| 734 | /* |
| 735 | * Station will be removed from device when the RXON |
| 736 | * is set to unassociated -- just deactivate it here |
| 737 | * to avoid re-programming it. |
| 738 | */ |
| 739 | ret = 0; |
| 740 | iwl_deactivate_station(priv, sta_priv->sta_id, sta->addr); |
| 741 | } else { |
| 742 | ret = iwl_remove_station(priv, sta_priv->sta_id, sta->addr); |
| 743 | if (ret) |
| 744 | IWL_DEBUG_QUIET_RFKILL(priv, |
| 745 | "Error removing station %pM\n", sta->addr); |
| 746 | } |
Johannes Berg | fb5fe5b | 2012-03-05 11:24:29 -0800 | [diff] [blame] | 747 | return ret; |
| 748 | } |
| 749 | |
David Spinadel | 50c1e9a | 2012-04-16 14:43:30 -0700 | [diff] [blame] | 750 | int iwlagn_mac_sta_state(struct ieee80211_hw *hw, |
| 751 | struct ieee80211_vif *vif, |
| 752 | struct ieee80211_sta *sta, |
| 753 | enum ieee80211_sta_state old_state, |
| 754 | enum ieee80211_sta_state new_state) |
Johannes Berg | fb5fe5b | 2012-03-05 11:24:29 -0800 | [diff] [blame] | 755 | { |
| 756 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
Johannes Berg | ab0bd5b | 2012-03-05 11:24:47 -0800 | [diff] [blame] | 757 | struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv; |
Johannes Berg | fb5fe5b | 2012-03-05 11:24:29 -0800 | [diff] [blame] | 758 | enum { |
Johannes Berg | ab0bd5b | 2012-03-05 11:24:47 -0800 | [diff] [blame] | 759 | NONE, ADD, REMOVE, HT_RATE_INIT, ADD_RATE_INIT, |
Johannes Berg | fb5fe5b | 2012-03-05 11:24:29 -0800 | [diff] [blame] | 760 | } op = NONE; |
| 761 | int ret; |
| 762 | |
| 763 | IWL_DEBUG_MAC80211(priv, "station %pM state change %d->%d\n", |
| 764 | sta->addr, old_state, new_state); |
| 765 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 766 | mutex_lock(&priv->mutex); |
Johannes Berg | fb5fe5b | 2012-03-05 11:24:29 -0800 | [diff] [blame] | 767 | if (vif->type == NL80211_IFTYPE_STATION) { |
| 768 | if (old_state == IEEE80211_STA_NOTEXIST && |
| 769 | new_state == IEEE80211_STA_NONE) |
| 770 | op = ADD; |
| 771 | else if (old_state == IEEE80211_STA_NONE && |
| 772 | new_state == IEEE80211_STA_NOTEXIST) |
| 773 | op = REMOVE; |
| 774 | else if (old_state == IEEE80211_STA_AUTH && |
| 775 | new_state == IEEE80211_STA_ASSOC) |
Johannes Berg | ab0bd5b | 2012-03-05 11:24:47 -0800 | [diff] [blame] | 776 | op = HT_RATE_INIT; |
Johannes Berg | fb5fe5b | 2012-03-05 11:24:29 -0800 | [diff] [blame] | 777 | } else { |
| 778 | if (old_state == IEEE80211_STA_AUTH && |
| 779 | new_state == IEEE80211_STA_ASSOC) |
| 780 | op = ADD_RATE_INIT; |
| 781 | else if (old_state == IEEE80211_STA_ASSOC && |
| 782 | new_state == IEEE80211_STA_AUTH) |
| 783 | op = REMOVE; |
| 784 | } |
| 785 | |
| 786 | switch (op) { |
| 787 | case ADD: |
| 788 | ret = iwlagn_mac_sta_add(hw, vif, sta); |
| 789 | break; |
| 790 | case REMOVE: |
| 791 | ret = iwlagn_mac_sta_remove(hw, vif, sta); |
| 792 | break; |
| 793 | case ADD_RATE_INIT: |
| 794 | ret = iwlagn_mac_sta_add(hw, vif, sta); |
| 795 | if (ret) |
| 796 | break; |
Johannes Berg | fb5fe5b | 2012-03-05 11:24:29 -0800 | [diff] [blame] | 797 | /* Initialize rate scaling */ |
| 798 | IWL_DEBUG_INFO(priv, |
| 799 | "Initializing rate scaling for station %pM\n", |
| 800 | sta->addr); |
| 801 | iwl_rs_rate_init(priv, sta, iwl_sta_id(sta)); |
| 802 | ret = 0; |
| 803 | break; |
Johannes Berg | ab0bd5b | 2012-03-05 11:24:47 -0800 | [diff] [blame] | 804 | case HT_RATE_INIT: |
| 805 | /* Initialize rate scaling */ |
| 806 | ret = iwl_sta_update_ht(priv, vif_priv->ctx, sta); |
| 807 | if (ret) |
| 808 | break; |
| 809 | IWL_DEBUG_INFO(priv, |
| 810 | "Initializing rate scaling for station %pM\n", |
| 811 | sta->addr); |
| 812 | iwl_rs_rate_init(priv, sta, iwl_sta_id(sta)); |
| 813 | ret = 0; |
| 814 | break; |
Johannes Berg | fb5fe5b | 2012-03-05 11:24:29 -0800 | [diff] [blame] | 815 | default: |
| 816 | ret = 0; |
| 817 | break; |
| 818 | } |
| 819 | |
| 820 | /* |
| 821 | * mac80211 might WARN if we fail, but due the way we |
| 822 | * (badly) handle hard rfkill, we might fail here |
| 823 | */ |
Don Fry | 8362640 | 2012-03-07 09:52:37 -0800 | [diff] [blame] | 824 | if (iwl_is_rfkill(priv)) |
Johannes Berg | fb5fe5b | 2012-03-05 11:24:29 -0800 | [diff] [blame] | 825 | ret = 0; |
| 826 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 827 | mutex_unlock(&priv->mutex); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 828 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
| 829 | |
| 830 | return ret; |
| 831 | } |
| 832 | |
David Spinadel | 50c1e9a | 2012-04-16 14:43:30 -0700 | [diff] [blame] | 833 | void iwlagn_mac_channel_switch(struct ieee80211_hw *hw, |
| 834 | struct ieee80211_channel_switch *ch_switch) |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 835 | { |
Emmanuel Grumbach | d0f76d6 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 836 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 837 | const struct iwl_channel_info *ch_info; |
| 838 | struct ieee80211_conf *conf = &hw->conf; |
| 839 | struct ieee80211_channel *channel = ch_switch->channel; |
| 840 | struct iwl_ht_config *ht_conf = &priv->current_ht_config; |
| 841 | /* |
| 842 | * MULTI-FIXME |
| 843 | * When we add support for multiple interfaces, we need to |
| 844 | * revisit this. The channel switch command in the device |
| 845 | * only affects the BSS context, but what does that really |
| 846 | * mean? And what if we get a CSA on the second interface? |
| 847 | * This needs a lot of work. |
| 848 | */ |
| 849 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; |
| 850 | u16 ch; |
| 851 | |
| 852 | IWL_DEBUG_MAC80211(priv, "enter\n"); |
| 853 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 854 | mutex_lock(&priv->mutex); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 855 | |
Don Fry | 8362640 | 2012-03-07 09:52:37 -0800 | [diff] [blame] | 856 | if (iwl_is_rfkill(priv)) |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 857 | goto out; |
| 858 | |
Don Fry | 8362640 | 2012-03-07 09:52:37 -0800 | [diff] [blame] | 859 | if (test_bit(STATUS_EXIT_PENDING, &priv->status) || |
| 860 | test_bit(STATUS_SCANNING, &priv->status) || |
| 861 | test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status)) |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 862 | goto out; |
| 863 | |
| 864 | if (!iwl_is_associated_ctx(ctx)) |
| 865 | goto out; |
| 866 | |
Johannes Berg | e967669 | 2012-04-10 14:10:28 -0700 | [diff] [blame] | 867 | if (!priv->lib->set_channel_switch) |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 868 | goto out; |
| 869 | |
| 870 | ch = channel->hw_value; |
| 871 | if (le16_to_cpu(ctx->active.channel) == ch) |
| 872 | goto out; |
| 873 | |
| 874 | ch_info = iwl_get_channel_info(priv, channel->band, ch); |
| 875 | if (!is_channel_valid(ch_info)) { |
| 876 | IWL_DEBUG_MAC80211(priv, "invalid channel\n"); |
| 877 | goto out; |
| 878 | } |
| 879 | |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 880 | priv->current_ht_config.smps = conf->smps_mode; |
| 881 | |
| 882 | /* Configure HT40 channels */ |
| 883 | ctx->ht.enabled = conf_is_ht(conf); |
Wey-Yi Guy | 137ce79 | 2011-11-22 16:23:35 -0800 | [diff] [blame] | 884 | if (ctx->ht.enabled) |
| 885 | iwlagn_config_ht40(conf, ctx); |
| 886 | else |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 887 | ctx->ht.is_40mhz = false; |
| 888 | |
| 889 | if ((le16_to_cpu(ctx->staging.channel) != ch)) |
| 890 | ctx->staging.flags = 0; |
| 891 | |
| 892 | iwl_set_rxon_channel(priv, channel, ctx); |
| 893 | iwl_set_rxon_ht(priv, ht_conf); |
| 894 | iwl_set_flags_for_band(priv, ctx, channel->band, ctx->vif); |
| 895 | |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 896 | /* |
| 897 | * at this point, staging_rxon has the |
| 898 | * configuration for channel switch |
| 899 | */ |
Don Fry | 8362640 | 2012-03-07 09:52:37 -0800 | [diff] [blame] | 900 | set_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 901 | priv->switch_channel = cpu_to_le16(ch); |
Johannes Berg | e967669 | 2012-04-10 14:10:28 -0700 | [diff] [blame] | 902 | if (priv->lib->set_channel_switch(priv, ch_switch)) { |
Don Fry | 8362640 | 2012-03-07 09:52:37 -0800 | [diff] [blame] | 903 | clear_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 904 | priv->switch_channel = 0; |
| 905 | ieee80211_chswitch_done(ctx->vif, false); |
| 906 | } |
| 907 | |
| 908 | out: |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 909 | mutex_unlock(&priv->mutex); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 910 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
| 911 | } |
| 912 | |
Meenakshi Venkataraman | bedec3a | 2012-03-13 17:47:23 -0700 | [diff] [blame] | 913 | void iwl_chswitch_done(struct iwl_priv *priv, bool is_success) |
| 914 | { |
| 915 | /* |
| 916 | * MULTI-FIXME |
| 917 | * See iwlagn_mac_channel_switch. |
| 918 | */ |
| 919 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; |
| 920 | |
| 921 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 922 | return; |
| 923 | |
| 924 | if (test_and_clear_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status)) |
| 925 | ieee80211_chswitch_done(ctx->vif, is_success); |
| 926 | } |
| 927 | |
David Spinadel | 50c1e9a | 2012-04-16 14:43:30 -0700 | [diff] [blame] | 928 | void iwlagn_configure_filter(struct ieee80211_hw *hw, |
| 929 | unsigned int changed_flags, |
| 930 | unsigned int *total_flags, |
| 931 | u64 multicast) |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 932 | { |
Emmanuel Grumbach | d0f76d6 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 933 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 934 | __le32 filter_or = 0, filter_nand = 0; |
| 935 | struct iwl_rxon_context *ctx; |
| 936 | |
| 937 | #define CHK(test, flag) do { \ |
| 938 | if (*total_flags & (test)) \ |
| 939 | filter_or |= (flag); \ |
| 940 | else \ |
| 941 | filter_nand |= (flag); \ |
| 942 | } while (0) |
| 943 | |
| 944 | IWL_DEBUG_MAC80211(priv, "Enter: changed: 0x%x, total: 0x%x\n", |
| 945 | changed_flags, *total_flags); |
| 946 | |
| 947 | CHK(FIF_OTHER_BSS | FIF_PROMISC_IN_BSS, RXON_FILTER_PROMISC_MSK); |
| 948 | /* Setting _just_ RXON_FILTER_CTL2HOST_MSK causes FH errors */ |
| 949 | CHK(FIF_CONTROL, RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_PROMISC_MSK); |
| 950 | CHK(FIF_BCN_PRBRESP_PROMISC, RXON_FILTER_BCON_AWARE_MSK); |
| 951 | |
| 952 | #undef CHK |
| 953 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 954 | mutex_lock(&priv->mutex); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 955 | |
| 956 | for_each_context(priv, ctx) { |
| 957 | ctx->staging.filter_flags &= ~filter_nand; |
| 958 | ctx->staging.filter_flags |= filter_or; |
| 959 | |
| 960 | /* |
| 961 | * Not committing directly because hardware can perform a scan, |
| 962 | * but we'll eventually commit the filter flags change anyway. |
| 963 | */ |
| 964 | } |
| 965 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 966 | mutex_unlock(&priv->mutex); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 967 | |
| 968 | /* |
| 969 | * Receiving all multicast frames is always enabled by the |
| 970 | * default flags setup in iwl_connection_init_rx_config() |
| 971 | * since we currently do not support programming multicast |
| 972 | * filters into the device. |
| 973 | */ |
| 974 | *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS | |
| 975 | FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL; |
| 976 | } |
| 977 | |
David Spinadel | 50c1e9a | 2012-04-16 14:43:30 -0700 | [diff] [blame] | 978 | void iwlagn_mac_flush(struct ieee80211_hw *hw, bool drop) |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 979 | { |
Emmanuel Grumbach | d0f76d6 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 980 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 981 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 982 | mutex_lock(&priv->mutex); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 983 | IWL_DEBUG_MAC80211(priv, "enter\n"); |
| 984 | |
Don Fry | 8362640 | 2012-03-07 09:52:37 -0800 | [diff] [blame] | 985 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 986 | IWL_DEBUG_TX(priv, "Aborting flush due to device shutdown\n"); |
| 987 | goto done; |
| 988 | } |
Don Fry | 8362640 | 2012-03-07 09:52:37 -0800 | [diff] [blame] | 989 | if (iwl_is_rfkill(priv)) { |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 990 | IWL_DEBUG_TX(priv, "Aborting flush due to RF Kill\n"); |
| 991 | goto done; |
| 992 | } |
| 993 | |
| 994 | /* |
| 995 | * mac80211 will not push any more frames for transmit |
| 996 | * until the flush is completed |
| 997 | */ |
| 998 | if (drop) { |
| 999 | IWL_DEBUG_MAC80211(priv, "send flush command\n"); |
| 1000 | if (iwlagn_txfifo_flush(priv, IWL_DROP_ALL)) { |
| 1001 | IWL_ERR(priv, "flush request fail\n"); |
| 1002 | goto done; |
| 1003 | } |
| 1004 | } |
| 1005 | IWL_DEBUG_MAC80211(priv, "wait transmit/flush all frames\n"); |
Emmanuel Grumbach | 68e8dfd | 2012-04-18 07:28:17 -0700 | [diff] [blame] | 1006 | iwl_trans_wait_tx_queue_empty(priv->trans); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 1007 | done: |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1008 | mutex_unlock(&priv->mutex); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 1009 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
| 1010 | } |
| 1011 | |
| 1012 | static int iwlagn_mac_remain_on_channel(struct ieee80211_hw *hw, |
| 1013 | struct ieee80211_channel *channel, |
| 1014 | enum nl80211_channel_type channel_type, |
| 1015 | int duration) |
| 1016 | { |
Emmanuel Grumbach | d0f76d6 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 1017 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 1018 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_PAN]; |
| 1019 | int err = 0; |
| 1020 | |
Johannes Berg | a18f61b | 2012-03-15 13:26:53 -0700 | [diff] [blame] | 1021 | if (!(priv->valid_contexts & BIT(IWL_RXON_CTX_PAN))) |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 1022 | return -EOPNOTSUPP; |
| 1023 | |
| 1024 | if (!(ctx->interface_modes & BIT(NL80211_IFTYPE_P2P_CLIENT))) |
| 1025 | return -EOPNOTSUPP; |
| 1026 | |
| 1027 | IWL_DEBUG_MAC80211(priv, "enter\n"); |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1028 | mutex_lock(&priv->mutex); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 1029 | |
Don Fry | 8362640 | 2012-03-07 09:52:37 -0800 | [diff] [blame] | 1030 | if (test_bit(STATUS_SCAN_HW, &priv->status)) { |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 1031 | err = -EBUSY; |
| 1032 | goto out; |
| 1033 | } |
| 1034 | |
| 1035 | priv->hw_roc_channel = channel; |
| 1036 | priv->hw_roc_chantype = channel_type; |
Johannes Berg | 3ddf6be | 2011-11-10 06:55:21 -0800 | [diff] [blame] | 1037 | /* convert from ms to TU */ |
| 1038 | priv->hw_roc_duration = DIV_ROUND_UP(1000 * duration, 1024); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 1039 | priv->hw_roc_start_notified = false; |
| 1040 | cancel_delayed_work(&priv->hw_roc_disable_work); |
| 1041 | |
| 1042 | if (!ctx->is_active) { |
Johannes Berg | a69cd04 | 2011-11-10 06:55:13 -0800 | [diff] [blame] | 1043 | static const struct iwl_qos_info default_qos_data = { |
| 1044 | .def_qos_parm = { |
| 1045 | .ac[0] = { |
| 1046 | .cw_min = cpu_to_le16(3), |
| 1047 | .cw_max = cpu_to_le16(7), |
| 1048 | .aifsn = 2, |
| 1049 | .edca_txop = cpu_to_le16(1504), |
| 1050 | }, |
| 1051 | .ac[1] = { |
| 1052 | .cw_min = cpu_to_le16(7), |
| 1053 | .cw_max = cpu_to_le16(15), |
| 1054 | .aifsn = 2, |
| 1055 | .edca_txop = cpu_to_le16(3008), |
| 1056 | }, |
| 1057 | .ac[2] = { |
| 1058 | .cw_min = cpu_to_le16(15), |
| 1059 | .cw_max = cpu_to_le16(1023), |
| 1060 | .aifsn = 3, |
| 1061 | }, |
| 1062 | .ac[3] = { |
| 1063 | .cw_min = cpu_to_le16(15), |
| 1064 | .cw_max = cpu_to_le16(1023), |
| 1065 | .aifsn = 7, |
| 1066 | }, |
| 1067 | }, |
| 1068 | }; |
| 1069 | |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 1070 | ctx->is_active = true; |
Johannes Berg | a69cd04 | 2011-11-10 06:55:13 -0800 | [diff] [blame] | 1071 | ctx->qos_data = default_qos_data; |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 1072 | ctx->staging.dev_type = RXON_DEV_TYPE_P2P; |
| 1073 | memcpy(ctx->staging.node_addr, |
| 1074 | priv->contexts[IWL_RXON_CTX_BSS].staging.node_addr, |
| 1075 | ETH_ALEN); |
| 1076 | memcpy(ctx->staging.bssid_addr, |
| 1077 | priv->contexts[IWL_RXON_CTX_BSS].staging.node_addr, |
| 1078 | ETH_ALEN); |
| 1079 | err = iwlagn_commit_rxon(priv, ctx); |
| 1080 | if (err) |
| 1081 | goto out; |
| 1082 | ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK | |
| 1083 | RXON_FILTER_PROMISC_MSK | |
| 1084 | RXON_FILTER_CTL2HOST_MSK; |
| 1085 | |
| 1086 | err = iwlagn_commit_rxon(priv, ctx); |
| 1087 | if (err) { |
| 1088 | iwlagn_disable_roc(priv); |
| 1089 | goto out; |
| 1090 | } |
| 1091 | priv->hw_roc_setup = true; |
| 1092 | } |
| 1093 | |
| 1094 | err = iwl_scan_initiate(priv, ctx->vif, IWL_SCAN_ROC, channel->band); |
| 1095 | if (err) |
| 1096 | iwlagn_disable_roc(priv); |
| 1097 | |
| 1098 | out: |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1099 | mutex_unlock(&priv->mutex); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 1100 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
| 1101 | |
| 1102 | return err; |
| 1103 | } |
| 1104 | |
David Spinadel | 50c1e9a | 2012-04-16 14:43:30 -0700 | [diff] [blame] | 1105 | int iwlagn_mac_cancel_remain_on_channel(struct ieee80211_hw *hw) |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 1106 | { |
Emmanuel Grumbach | d0f76d6 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 1107 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 1108 | |
Johannes Berg | a18f61b | 2012-03-15 13:26:53 -0700 | [diff] [blame] | 1109 | if (!(priv->valid_contexts & BIT(IWL_RXON_CTX_PAN))) |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 1110 | return -EOPNOTSUPP; |
| 1111 | |
| 1112 | IWL_DEBUG_MAC80211(priv, "enter\n"); |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1113 | mutex_lock(&priv->mutex); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 1114 | iwl_scan_cancel_timeout(priv, priv->hw_roc_duration); |
| 1115 | iwlagn_disable_roc(priv); |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1116 | mutex_unlock(&priv->mutex); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 1117 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
| 1118 | |
| 1119 | return 0; |
| 1120 | } |
| 1121 | |
David Spinadel | 50c1e9a | 2012-04-16 14:43:30 -0700 | [diff] [blame] | 1122 | void iwlagn_mac_rssi_callback(struct ieee80211_hw *hw, |
| 1123 | enum ieee80211_rssi_event rssi_event) |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 1124 | { |
Emmanuel Grumbach | d0f76d6 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 1125 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 1126 | |
| 1127 | IWL_DEBUG_MAC80211(priv, "enter\n"); |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1128 | mutex_lock(&priv->mutex); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 1129 | |
Emmanuel Grumbach | 2152268 | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 1130 | if (priv->cfg->bt_params && |
| 1131 | priv->cfg->bt_params->advanced_bt_coexist) { |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 1132 | if (rssi_event == RSSI_EVENT_LOW) |
| 1133 | priv->bt_enable_pspoll = true; |
| 1134 | else if (rssi_event == RSSI_EVENT_HIGH) |
| 1135 | priv->bt_enable_pspoll = false; |
| 1136 | |
| 1137 | iwlagn_send_advance_bt_config(priv); |
| 1138 | } else { |
| 1139 | IWL_DEBUG_MAC80211(priv, "Advanced BT coex disabled," |
| 1140 | "ignoring RSSI callback\n"); |
| 1141 | } |
| 1142 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1143 | mutex_unlock(&priv->mutex); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 1144 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
| 1145 | } |
| 1146 | |
David Spinadel | 50c1e9a | 2012-04-16 14:43:30 -0700 | [diff] [blame] | 1147 | int iwlagn_mac_set_tim(struct ieee80211_hw *hw, |
| 1148 | struct ieee80211_sta *sta, bool set) |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 1149 | { |
Emmanuel Grumbach | d0f76d6 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 1150 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 1151 | |
Johannes Berg | 1ee158d | 2012-02-17 10:07:44 -0800 | [diff] [blame] | 1152 | queue_work(priv->workqueue, &priv->beacon_update); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 1153 | |
| 1154 | return 0; |
| 1155 | } |
| 1156 | |
David Spinadel | 50c1e9a | 2012-04-16 14:43:30 -0700 | [diff] [blame] | 1157 | int iwlagn_mac_conf_tx(struct ieee80211_hw *hw, |
| 1158 | struct ieee80211_vif *vif, u16 queue, |
| 1159 | const struct ieee80211_tx_queue_params *params) |
Wey-Yi Guy | 0b7a4c7 | 2011-11-10 06:55:14 -0800 | [diff] [blame] | 1160 | { |
Emmanuel Grumbach | d0f76d6 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 1161 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
Wey-Yi Guy | 0b7a4c7 | 2011-11-10 06:55:14 -0800 | [diff] [blame] | 1162 | struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv; |
| 1163 | struct iwl_rxon_context *ctx = vif_priv->ctx; |
Wey-Yi Guy | 0b7a4c7 | 2011-11-10 06:55:14 -0800 | [diff] [blame] | 1164 | int q; |
| 1165 | |
| 1166 | if (WARN_ON(!ctx)) |
| 1167 | return -EINVAL; |
| 1168 | |
| 1169 | IWL_DEBUG_MAC80211(priv, "enter\n"); |
| 1170 | |
Don Fry | 8362640 | 2012-03-07 09:52:37 -0800 | [diff] [blame] | 1171 | if (!iwl_is_ready_rf(priv)) { |
Wey-Yi Guy | 0b7a4c7 | 2011-11-10 06:55:14 -0800 | [diff] [blame] | 1172 | IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n"); |
| 1173 | return -EIO; |
| 1174 | } |
| 1175 | |
| 1176 | if (queue >= AC_NUM) { |
| 1177 | IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue); |
| 1178 | return 0; |
| 1179 | } |
| 1180 | |
| 1181 | q = AC_NUM - 1 - queue; |
| 1182 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1183 | mutex_lock(&priv->mutex); |
Wey-Yi Guy | 0b7a4c7 | 2011-11-10 06:55:14 -0800 | [diff] [blame] | 1184 | |
| 1185 | ctx->qos_data.def_qos_parm.ac[q].cw_min = |
| 1186 | cpu_to_le16(params->cw_min); |
| 1187 | ctx->qos_data.def_qos_parm.ac[q].cw_max = |
| 1188 | cpu_to_le16(params->cw_max); |
| 1189 | ctx->qos_data.def_qos_parm.ac[q].aifsn = params->aifs; |
| 1190 | ctx->qos_data.def_qos_parm.ac[q].edca_txop = |
| 1191 | cpu_to_le16((params->txop * 32)); |
| 1192 | |
| 1193 | ctx->qos_data.def_qos_parm.ac[q].reserved1 = 0; |
| 1194 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1195 | mutex_unlock(&priv->mutex); |
Wey-Yi Guy | 0b7a4c7 | 2011-11-10 06:55:14 -0800 | [diff] [blame] | 1196 | |
| 1197 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
| 1198 | return 0; |
| 1199 | } |
| 1200 | |
David Spinadel | 50c1e9a | 2012-04-16 14:43:30 -0700 | [diff] [blame] | 1201 | int iwlagn_mac_tx_last_beacon(struct ieee80211_hw *hw) |
Wey-Yi Guy | 0b7a4c7 | 2011-11-10 06:55:14 -0800 | [diff] [blame] | 1202 | { |
Emmanuel Grumbach | d0f76d6 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 1203 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
Wey-Yi Guy | 0b7a4c7 | 2011-11-10 06:55:14 -0800 | [diff] [blame] | 1204 | |
| 1205 | return priv->ibss_manager == IWL_IBSS_MANAGER; |
| 1206 | } |
| 1207 | |
| 1208 | static int iwl_set_mode(struct iwl_priv *priv, struct iwl_rxon_context *ctx) |
| 1209 | { |
| 1210 | iwl_connection_init_rx_config(priv, ctx); |
| 1211 | |
| 1212 | iwlagn_set_rxon_chain(priv, ctx); |
| 1213 | |
| 1214 | return iwlagn_commit_rxon(priv, ctx); |
| 1215 | } |
| 1216 | |
David Spinadel | 50c1e9a | 2012-04-16 14:43:30 -0700 | [diff] [blame] | 1217 | int iwl_setup_interface(struct iwl_priv *priv, struct iwl_rxon_context *ctx) |
Wey-Yi Guy | 0b7a4c7 | 2011-11-10 06:55:14 -0800 | [diff] [blame] | 1218 | { |
| 1219 | struct ieee80211_vif *vif = ctx->vif; |
| 1220 | int err; |
| 1221 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1222 | lockdep_assert_held(&priv->mutex); |
Wey-Yi Guy | 0b7a4c7 | 2011-11-10 06:55:14 -0800 | [diff] [blame] | 1223 | |
| 1224 | /* |
| 1225 | * This variable will be correct only when there's just |
| 1226 | * a single context, but all code using it is for hardware |
| 1227 | * that supports only one context. |
| 1228 | */ |
| 1229 | priv->iw_mode = vif->type; |
| 1230 | |
| 1231 | ctx->is_active = true; |
| 1232 | |
| 1233 | err = iwl_set_mode(priv, ctx); |
| 1234 | if (err) { |
| 1235 | if (!ctx->always_active) |
| 1236 | ctx->is_active = false; |
| 1237 | return err; |
| 1238 | } |
| 1239 | |
Emmanuel Grumbach | 2152268 | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 1240 | if (priv->cfg->bt_params && priv->cfg->bt_params->advanced_bt_coexist && |
Wey-Yi Guy | 0b7a4c7 | 2011-11-10 06:55:14 -0800 | [diff] [blame] | 1241 | vif->type == NL80211_IFTYPE_ADHOC) { |
| 1242 | /* |
| 1243 | * pretend to have high BT traffic as long as we |
| 1244 | * are operating in IBSS mode, as this will cause |
| 1245 | * the rate scaling etc. to behave as intended. |
| 1246 | */ |
| 1247 | priv->bt_traffic_load = IWL_BT_COEX_TRAFFIC_LOAD_HIGH; |
| 1248 | } |
| 1249 | |
| 1250 | return 0; |
| 1251 | } |
| 1252 | |
| 1253 | static int iwlagn_mac_add_interface(struct ieee80211_hw *hw, |
| 1254 | struct ieee80211_vif *vif) |
| 1255 | { |
Emmanuel Grumbach | d0f76d6 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 1256 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
Wey-Yi Guy | 0b7a4c7 | 2011-11-10 06:55:14 -0800 | [diff] [blame] | 1257 | struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv; |
| 1258 | struct iwl_rxon_context *tmp, *ctx = NULL; |
| 1259 | int err; |
| 1260 | enum nl80211_iftype viftype = ieee80211_vif_type_p2p(vif); |
| 1261 | |
| 1262 | IWL_DEBUG_MAC80211(priv, "enter: type %d, addr %pM\n", |
| 1263 | viftype, vif->addr); |
| 1264 | |
| 1265 | cancel_delayed_work_sync(&priv->hw_roc_disable_work); |
| 1266 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1267 | mutex_lock(&priv->mutex); |
Wey-Yi Guy | 0b7a4c7 | 2011-11-10 06:55:14 -0800 | [diff] [blame] | 1268 | |
| 1269 | iwlagn_disable_roc(priv); |
| 1270 | |
Don Fry | 8362640 | 2012-03-07 09:52:37 -0800 | [diff] [blame] | 1271 | if (!iwl_is_ready_rf(priv)) { |
Wey-Yi Guy | 0b7a4c7 | 2011-11-10 06:55:14 -0800 | [diff] [blame] | 1272 | IWL_WARN(priv, "Try to add interface when device not ready\n"); |
| 1273 | err = -EINVAL; |
| 1274 | goto out; |
| 1275 | } |
| 1276 | |
| 1277 | for_each_context(priv, tmp) { |
| 1278 | u32 possible_modes = |
| 1279 | tmp->interface_modes | tmp->exclusive_interface_modes; |
| 1280 | |
| 1281 | if (tmp->vif) { |
| 1282 | /* check if this busy context is exclusive */ |
| 1283 | if (tmp->exclusive_interface_modes & |
| 1284 | BIT(tmp->vif->type)) { |
| 1285 | err = -EINVAL; |
| 1286 | goto out; |
| 1287 | } |
| 1288 | continue; |
| 1289 | } |
| 1290 | |
| 1291 | if (!(possible_modes & BIT(viftype))) |
| 1292 | continue; |
| 1293 | |
| 1294 | /* have maybe usable context w/o interface */ |
| 1295 | ctx = tmp; |
| 1296 | break; |
| 1297 | } |
| 1298 | |
| 1299 | if (!ctx) { |
| 1300 | err = -EOPNOTSUPP; |
| 1301 | goto out; |
| 1302 | } |
| 1303 | |
| 1304 | vif_priv->ctx = ctx; |
| 1305 | ctx->vif = vif; |
| 1306 | |
| 1307 | err = iwl_setup_interface(priv, ctx); |
| 1308 | if (!err) |
| 1309 | goto out; |
| 1310 | |
| 1311 | ctx->vif = NULL; |
| 1312 | priv->iw_mode = NL80211_IFTYPE_STATION; |
| 1313 | out: |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1314 | mutex_unlock(&priv->mutex); |
Wey-Yi Guy | 0b7a4c7 | 2011-11-10 06:55:14 -0800 | [diff] [blame] | 1315 | |
| 1316 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
| 1317 | return err; |
| 1318 | } |
| 1319 | |
David Spinadel | 50c1e9a | 2012-04-16 14:43:30 -0700 | [diff] [blame] | 1320 | void iwl_teardown_interface(struct iwl_priv *priv, |
| 1321 | struct ieee80211_vif *vif, |
| 1322 | bool mode_change) |
Wey-Yi Guy | 0b7a4c7 | 2011-11-10 06:55:14 -0800 | [diff] [blame] | 1323 | { |
| 1324 | struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif); |
| 1325 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1326 | lockdep_assert_held(&priv->mutex); |
Wey-Yi Guy | 0b7a4c7 | 2011-11-10 06:55:14 -0800 | [diff] [blame] | 1327 | |
| 1328 | if (priv->scan_vif == vif) { |
| 1329 | iwl_scan_cancel_timeout(priv, 200); |
| 1330 | iwl_force_scan_end(priv); |
| 1331 | } |
| 1332 | |
| 1333 | if (!mode_change) { |
| 1334 | iwl_set_mode(priv, ctx); |
| 1335 | if (!ctx->always_active) |
| 1336 | ctx->is_active = false; |
| 1337 | } |
| 1338 | |
| 1339 | /* |
| 1340 | * When removing the IBSS interface, overwrite the |
| 1341 | * BT traffic load with the stored one from the last |
| 1342 | * notification, if any. If this is a device that |
| 1343 | * doesn't implement this, this has no effect since |
| 1344 | * both values are the same and zero. |
| 1345 | */ |
| 1346 | if (vif->type == NL80211_IFTYPE_ADHOC) |
| 1347 | priv->bt_traffic_load = priv->last_bt_traffic_load; |
| 1348 | } |
| 1349 | |
| 1350 | static void iwlagn_mac_remove_interface(struct ieee80211_hw *hw, |
| 1351 | struct ieee80211_vif *vif) |
| 1352 | { |
Emmanuel Grumbach | d0f76d6 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 1353 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
Wey-Yi Guy | 0b7a4c7 | 2011-11-10 06:55:14 -0800 | [diff] [blame] | 1354 | struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif); |
| 1355 | |
| 1356 | IWL_DEBUG_MAC80211(priv, "enter\n"); |
| 1357 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1358 | mutex_lock(&priv->mutex); |
Wey-Yi Guy | 0b7a4c7 | 2011-11-10 06:55:14 -0800 | [diff] [blame] | 1359 | |
| 1360 | if (WARN_ON(ctx->vif != vif)) { |
| 1361 | struct iwl_rxon_context *tmp; |
| 1362 | IWL_ERR(priv, "ctx->vif = %p, vif = %p\n", ctx->vif, vif); |
| 1363 | for_each_context(priv, tmp) |
| 1364 | IWL_ERR(priv, "\tID = %d:\tctx = %p\tctx->vif = %p\n", |
| 1365 | tmp->ctxid, tmp, tmp->vif); |
| 1366 | } |
| 1367 | ctx->vif = NULL; |
| 1368 | |
| 1369 | iwl_teardown_interface(priv, vif, false); |
| 1370 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1371 | mutex_unlock(&priv->mutex); |
Wey-Yi Guy | 0b7a4c7 | 2011-11-10 06:55:14 -0800 | [diff] [blame] | 1372 | |
| 1373 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
| 1374 | |
| 1375 | } |
| 1376 | |
| 1377 | static int iwlagn_mac_change_interface(struct ieee80211_hw *hw, |
| 1378 | struct ieee80211_vif *vif, |
| 1379 | enum nl80211_iftype newtype, bool newp2p) |
| 1380 | { |
Emmanuel Grumbach | d0f76d6 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 1381 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
Wey-Yi Guy | 0b7a4c7 | 2011-11-10 06:55:14 -0800 | [diff] [blame] | 1382 | struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif); |
| 1383 | struct iwl_rxon_context *bss_ctx = &priv->contexts[IWL_RXON_CTX_BSS]; |
| 1384 | struct iwl_rxon_context *tmp; |
| 1385 | enum nl80211_iftype newviftype = newtype; |
| 1386 | u32 interface_modes; |
| 1387 | int err; |
| 1388 | |
| 1389 | IWL_DEBUG_MAC80211(priv, "enter\n"); |
| 1390 | |
| 1391 | newtype = ieee80211_iftype_p2p(newtype, newp2p); |
| 1392 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1393 | mutex_lock(&priv->mutex); |
Wey-Yi Guy | 0b7a4c7 | 2011-11-10 06:55:14 -0800 | [diff] [blame] | 1394 | |
Don Fry | 8362640 | 2012-03-07 09:52:37 -0800 | [diff] [blame] | 1395 | if (!ctx->vif || !iwl_is_ready_rf(priv)) { |
Wey-Yi Guy | 0b7a4c7 | 2011-11-10 06:55:14 -0800 | [diff] [blame] | 1396 | /* |
| 1397 | * Huh? But wait ... this can maybe happen when |
| 1398 | * we're in the middle of a firmware restart! |
| 1399 | */ |
| 1400 | err = -EBUSY; |
| 1401 | goto out; |
| 1402 | } |
| 1403 | |
| 1404 | interface_modes = ctx->interface_modes | ctx->exclusive_interface_modes; |
| 1405 | |
| 1406 | if (!(interface_modes & BIT(newtype))) { |
| 1407 | err = -EBUSY; |
| 1408 | goto out; |
| 1409 | } |
| 1410 | |
| 1411 | /* |
| 1412 | * Refuse a change that should be done by moving from the PAN |
| 1413 | * context to the BSS context instead, if the BSS context is |
| 1414 | * available and can support the new interface type. |
| 1415 | */ |
| 1416 | if (ctx->ctxid == IWL_RXON_CTX_PAN && !bss_ctx->vif && |
| 1417 | (bss_ctx->interface_modes & BIT(newtype) || |
| 1418 | bss_ctx->exclusive_interface_modes & BIT(newtype))) { |
| 1419 | BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2); |
| 1420 | err = -EBUSY; |
| 1421 | goto out; |
| 1422 | } |
| 1423 | |
| 1424 | if (ctx->exclusive_interface_modes & BIT(newtype)) { |
| 1425 | for_each_context(priv, tmp) { |
| 1426 | if (ctx == tmp) |
| 1427 | continue; |
| 1428 | |
| 1429 | if (!tmp->vif) |
| 1430 | continue; |
| 1431 | |
| 1432 | /* |
| 1433 | * The current mode switch would be exclusive, but |
| 1434 | * another context is active ... refuse the switch. |
| 1435 | */ |
| 1436 | err = -EBUSY; |
| 1437 | goto out; |
| 1438 | } |
| 1439 | } |
| 1440 | |
| 1441 | /* success */ |
| 1442 | iwl_teardown_interface(priv, vif, true); |
| 1443 | vif->type = newviftype; |
| 1444 | vif->p2p = newp2p; |
| 1445 | err = iwl_setup_interface(priv, ctx); |
| 1446 | WARN_ON(err); |
| 1447 | /* |
| 1448 | * We've switched internally, but submitting to the |
| 1449 | * device may have failed for some reason. Mask this |
| 1450 | * error, because otherwise mac80211 will not switch |
| 1451 | * (and set the interface type back) and we'll be |
| 1452 | * out of sync with it. |
| 1453 | */ |
| 1454 | err = 0; |
| 1455 | |
| 1456 | out: |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1457 | mutex_unlock(&priv->mutex); |
Wey-Yi Guy | 0b7a4c7 | 2011-11-10 06:55:14 -0800 | [diff] [blame] | 1458 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
| 1459 | |
| 1460 | return err; |
| 1461 | } |
| 1462 | |
David Spinadel | 50c1e9a | 2012-04-16 14:43:30 -0700 | [diff] [blame] | 1463 | int iwlagn_mac_hw_scan(struct ieee80211_hw *hw, |
| 1464 | struct ieee80211_vif *vif, |
| 1465 | struct cfg80211_scan_request *req) |
Wey-Yi Guy | ba4c531 | 2011-11-10 06:55:15 -0800 | [diff] [blame] | 1466 | { |
Emmanuel Grumbach | d0f76d6 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 1467 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
Wey-Yi Guy | ba4c531 | 2011-11-10 06:55:15 -0800 | [diff] [blame] | 1468 | int ret; |
| 1469 | |
| 1470 | IWL_DEBUG_MAC80211(priv, "enter\n"); |
| 1471 | |
| 1472 | if (req->n_channels == 0) |
| 1473 | return -EINVAL; |
| 1474 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1475 | mutex_lock(&priv->mutex); |
Wey-Yi Guy | ba4c531 | 2011-11-10 06:55:15 -0800 | [diff] [blame] | 1476 | |
| 1477 | /* |
| 1478 | * If an internal scan is in progress, just set |
| 1479 | * up the scan_request as per above. |
| 1480 | */ |
| 1481 | if (priv->scan_type != IWL_SCAN_NORMAL) { |
| 1482 | IWL_DEBUG_SCAN(priv, |
| 1483 | "SCAN request during internal scan - defer\n"); |
| 1484 | priv->scan_request = req; |
| 1485 | priv->scan_vif = vif; |
| 1486 | ret = 0; |
| 1487 | } else { |
| 1488 | priv->scan_request = req; |
| 1489 | priv->scan_vif = vif; |
| 1490 | /* |
| 1491 | * mac80211 will only ask for one band at a time |
| 1492 | * so using channels[0] here is ok |
| 1493 | */ |
| 1494 | ret = iwl_scan_initiate(priv, vif, IWL_SCAN_NORMAL, |
| 1495 | req->channels[0]->band); |
| 1496 | if (ret) { |
| 1497 | priv->scan_request = NULL; |
| 1498 | priv->scan_vif = NULL; |
| 1499 | } |
| 1500 | } |
| 1501 | |
| 1502 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
| 1503 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1504 | mutex_unlock(&priv->mutex); |
Wey-Yi Guy | ba4c531 | 2011-11-10 06:55:15 -0800 | [diff] [blame] | 1505 | |
| 1506 | return ret; |
| 1507 | } |
| 1508 | |
Wey-Yi Guy | 76b2933 | 2011-11-10 06:55:16 -0800 | [diff] [blame] | 1509 | static void iwl_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id) |
| 1510 | { |
Johannes Berg | 9451ca1 | 2012-03-05 11:24:23 -0800 | [diff] [blame] | 1511 | struct iwl_addsta_cmd cmd = { |
| 1512 | .mode = STA_CONTROL_MODIFY_MSK, |
| 1513 | .station_flags_msk = STA_FLG_PWR_SAVE_MSK, |
| 1514 | .sta.sta_id = sta_id, |
| 1515 | }; |
Wey-Yi Guy | 76b2933 | 2011-11-10 06:55:16 -0800 | [diff] [blame] | 1516 | |
Johannes Berg | 9451ca1 | 2012-03-05 11:24:23 -0800 | [diff] [blame] | 1517 | iwl_send_add_sta(priv, &cmd, CMD_ASYNC); |
Wey-Yi Guy | 76b2933 | 2011-11-10 06:55:16 -0800 | [diff] [blame] | 1518 | } |
| 1519 | |
David Spinadel | 50c1e9a | 2012-04-16 14:43:30 -0700 | [diff] [blame] | 1520 | void iwlagn_mac_sta_notify(struct ieee80211_hw *hw, |
Wey-Yi Guy | 76b2933 | 2011-11-10 06:55:16 -0800 | [diff] [blame] | 1521 | struct ieee80211_vif *vif, |
| 1522 | enum sta_notify_cmd cmd, |
| 1523 | struct ieee80211_sta *sta) |
| 1524 | { |
Emmanuel Grumbach | d0f76d6 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 1525 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
Wey-Yi Guy | 76b2933 | 2011-11-10 06:55:16 -0800 | [diff] [blame] | 1526 | struct iwl_station_priv *sta_priv = (void *)sta->drv_priv; |
| 1527 | int sta_id; |
| 1528 | |
| 1529 | IWL_DEBUG_MAC80211(priv, "enter\n"); |
| 1530 | |
| 1531 | switch (cmd) { |
| 1532 | case STA_NOTIFY_SLEEP: |
| 1533 | WARN_ON(!sta_priv->client); |
| 1534 | sta_priv->asleep = true; |
| 1535 | if (atomic_read(&sta_priv->pending_frames) > 0) |
| 1536 | ieee80211_sta_block_awake(hw, sta, true); |
| 1537 | break; |
| 1538 | case STA_NOTIFY_AWAKE: |
| 1539 | WARN_ON(!sta_priv->client); |
| 1540 | if (!sta_priv->asleep) |
| 1541 | break; |
| 1542 | sta_priv->asleep = false; |
| 1543 | sta_id = iwl_sta_id(sta); |
| 1544 | if (sta_id != IWL_INVALID_STATION) |
| 1545 | iwl_sta_modify_ps_wake(priv, sta_id); |
| 1546 | break; |
| 1547 | default: |
| 1548 | break; |
| 1549 | } |
| 1550 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
| 1551 | } |
| 1552 | |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 1553 | struct ieee80211_ops iwlagn_hw_ops = { |
| 1554 | .tx = iwlagn_mac_tx, |
| 1555 | .start = iwlagn_mac_start, |
| 1556 | .stop = iwlagn_mac_stop, |
| 1557 | #ifdef CONFIG_PM_SLEEP |
| 1558 | .suspend = iwlagn_mac_suspend, |
| 1559 | .resume = iwlagn_mac_resume, |
| 1560 | #endif |
| 1561 | .add_interface = iwlagn_mac_add_interface, |
| 1562 | .remove_interface = iwlagn_mac_remove_interface, |
| 1563 | .change_interface = iwlagn_mac_change_interface, |
| 1564 | .config = iwlagn_mac_config, |
| 1565 | .configure_filter = iwlagn_configure_filter, |
| 1566 | .set_key = iwlagn_mac_set_key, |
| 1567 | .update_tkip_key = iwlagn_mac_update_tkip_key, |
| 1568 | .set_rekey_data = iwlagn_mac_set_rekey_data, |
| 1569 | .conf_tx = iwlagn_mac_conf_tx, |
| 1570 | .bss_info_changed = iwlagn_bss_info_changed, |
| 1571 | .ampdu_action = iwlagn_mac_ampdu_action, |
| 1572 | .hw_scan = iwlagn_mac_hw_scan, |
| 1573 | .sta_notify = iwlagn_mac_sta_notify, |
Johannes Berg | fb5fe5b | 2012-03-05 11:24:29 -0800 | [diff] [blame] | 1574 | .sta_state = iwlagn_mac_sta_state, |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 1575 | .channel_switch = iwlagn_mac_channel_switch, |
| 1576 | .flush = iwlagn_mac_flush, |
| 1577 | .tx_last_beacon = iwlagn_mac_tx_last_beacon, |
| 1578 | .remain_on_channel = iwlagn_mac_remain_on_channel, |
| 1579 | .cancel_remain_on_channel = iwlagn_mac_cancel_remain_on_channel, |
| 1580 | .rssi_callback = iwlagn_mac_rssi_callback, |
| 1581 | CFG80211_TESTMODE_CMD(iwlagn_mac_testmode_cmd) |
| 1582 | CFG80211_TESTMODE_DUMP(iwlagn_mac_testmode_dump) |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 1583 | .set_tim = iwlagn_mac_set_tim, |
| 1584 | }; |
| 1585 | |
| 1586 | /* This function both allocates and initializes hw and priv. */ |
| 1587 | struct ieee80211_hw *iwl_alloc_all(void) |
| 1588 | { |
| 1589 | struct iwl_priv *priv; |
Emmanuel Grumbach | d0f76d6 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 1590 | struct iwl_op_mode *op_mode; |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 1591 | /* mac80211 allocates memory for this device instance, including |
| 1592 | * space for this driver's private structure */ |
| 1593 | struct ieee80211_hw *hw; |
| 1594 | |
Emmanuel Grumbach | d0f76d6 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 1595 | hw = ieee80211_alloc_hw(sizeof(struct iwl_priv) + |
| 1596 | sizeof(struct iwl_op_mode), &iwlagn_hw_ops); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 1597 | if (!hw) |
| 1598 | goto out; |
| 1599 | |
Emmanuel Grumbach | d0f76d6 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 1600 | op_mode = hw->priv; |
| 1601 | priv = IWL_OP_MODE_GET_DVM(op_mode); |
Wey-Yi Guy | 7335613 | 2011-11-10 06:55:11 -0800 | [diff] [blame] | 1602 | priv->hw = hw; |
| 1603 | |
| 1604 | out: |
| 1605 | return hw; |
| 1606 | } |