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