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